overflow

3 位贡献者:

Summary

The overflow property specifies whether to clip content, render scrollbars or just display content when it overflows its block level container.

Using the overflow property with a value different to visible (its default) will create a new block formatting context. This is technically necessary — if a float intersected with the scrolling element it would forcibly rewrap the content. The rewrap would happen after each scroll step, leading to a slow scrolling experience.

Note: When programmatically setting scrollTop on the relevant HTML element, even when overflow has the hidden value an element may still need to scroll.

  • 初始值 visible
  • 适用元素 non-replaced block-level elements and non-replaced inline-block elements
  • 是否是继承属性 no
  • 适用媒体 visual
  • 计算值 as specified
  • 是否适用于 CSS 动画
  • 正规顺序 the unique non-ambiguous order defined by the formal grammar

Syntax

/* Content is not clipped */
overflow: visible;

/* Content is clipped, with no scrollbars */
overflow: hidden;

/* Content is clipped, with scrollbars */
overflow: scroll;

/* Let the browser decide */
overflow: auto;

overflow: inherit;
 
 
 
 
 
 
 
 
 
 
 
 
 

Values

visible
Default value. Content is not clipped, it may be rendered outside the content box.
hidden
The content is clipped and no scrollbars are provided.
scroll
The content is clipped and desktop browsers use scrollbars, whether or not any content is clipped. This avoids any problem with scrollbars appearing and disappearing in a dynamic environment. Printers may print overflowing content.
auto
Depends on the user agent. Desktop browsers like Firefox provide scrollbars if content overflows.

Mozilla Extensions

-moz-scrollbars-none 
Use overflow:hidden instead.
-moz-scrollbars-horizontal 
Use of overflow-x and overflow-y is preferred.
-moz-scrollbars-vertical 
Use of overflow-x and overflow-y is preferred.
-moz-hidden-unscrollable
Is intended mainly for internal use and by themes. Disables scrolling of XML root elements and <html><body> by arrow keys and mouse wheel.

Formal syntax

visible | hidden | scroll | auto

Examples

p {  
     width: 12em;
     height: 6em;
     border: dotted;
     overflow: visible; /* content is not clipped */ 
}
 
 
 
 
 
 

visible (default)
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.

p { overflow: hidden; /* no scrollbars are provided */ }
 

overflow: hidden
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.

p { overflow: scroll; /* always show scrollbars */ }
 

overflow: scroll
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.

p { overflow: auto; /* append scrollbars if necessary */ }
 

overflow: auto
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.

Specifications

Specification Status Comment
CSS Overflow Module Level 3
overflow
Working Draft  
CSS Basic Box Model
overflow
Working Draft No change.
CSS Level 2 (Revision 1)
overflow
Recommendation  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 1.0 (1.7 or earlier) 4.0 7.0 1.0 (85)
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support ? 1.0 (1) ? ? ?

Firefox (Gecko) Notes

Through Firefox 3.6 (Gecko 1.9.2), the overflow property is incorrectly applied to table-group elements (<thead> , <tbody> , <tfoot>). This behavior is corrected in later versions.

Internet Explorer Notes

Internet Explorer 4 to 6 enlarges an element with overflow:visible(default value) to fit the content inside it. height/width behaves like min-height/min-width.

See also

摘要

overflow 属性作用于 block 型元素上,它指定如何裁剪其内容,是否显示滚动条,以及如何显示超出它的大小的内容。

语法

overflow: visible | hidden | scroll | auto | inherit

取值

visible 
浏览器不对超出大小的内容进行裁剪,而是直接将超出的部分显示出来。
hidden 
裁剪超出大小的内容,且不显示滚动条。
auto 
超出大小后自动显示滚动条。
scroll 
不管是否有超出的内容,始终显示滚动条。这可以避免在一个动态变化的内容中滚动条在显示与隐藏间切换而造成的问题。
inherit
 

示例

查看在线演示

.sidebox {
  width: 300px;
  overflow: auto;
}

注释

规范

浏览器兼容性

(简单兼容性表)

游览器 最低版本
Internet Explorer ?
Firefox 1
Netscape ?
Opera ?
Safari ?

 

参见

overflow-x, overflow-y, clip, display

文档标签和贡献者

向此页面作出贡献: FredWe, teoli, TigerSoldier
最后编辑者: FredWe,