定义
overflow 属性设置当元素的内容溢出其区域时发生的事情。
继承性:No
说明
这个属性定义溢出元素内容区的内容会如何处理。如果值为 scroll,不论是否需要,用户代理都会提供一种滚动机制。因此,有可能即使元素框中可以放下所有内容也会出现滚动条。
值 | 描述 |
visible |
内容不会被修剪,会呈现在元素框之外。 |
hidden |
内容会被修剪,但是浏览器不会显示供查看内容的滚动条。 |
scroll |
内容会被修剪,但是浏览器会显示滚动条以便查看其余的内容。 |
auto |
由浏览器决定如何显示。如果需要,则显示滚动条。 |
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>About Overflow</title>
<style type="text/css">
div{height:60px;width:200px;background:#f0f;margin:100px;}
.overflow1{overflow: visible;}
.overflow2{overflow: hidden;}
.overflow3{overflow: scroll;}
.overflow4{overflow: auto;}
</style>
</head>
<body>
<div class="overflow1">
overflow: visible;<br/>
this is a test about css.<br/>
height: 100px;<br/>
200px;<br/>
</div>
<div class="overflow2">
overflow: hidden;<br/>
this is a test about css.<br/>
height: 100px;<br/>
200px;<br/>
</div>
<div class="overflow3">
overflow: scroll;<br/>
this is a test about css.<br/>
height: 100px;<br/>
200px;<br/>
</div>
<div class="overflow4">
overflow: auto;<br/>
this is a test about css.<br/>
height: 100px;<br/>
200px;<br/>
</div>
</body>
</html>
代码是关于四个属性的演示。
值得注意的是这是在主流的ff和ie都能实现的效果。此外,还有一个很诱人的效果,不过只能在IE6+上被支持,就是text-overflow。
语法:
text-overflow : clip | ellipsis
参数:
clip : 不显示省略标记(...),而是简单的裁切
ellipsis : 当对象内文本溢出时显示省略标记(...)
很多人的设法让这个效果在ff里也实现,详细的我觉得用google搜索就行。
个人觉得text-overflow现在不使用,哪天W3C把它列入标准了,浏览器都支持了,再使用会比较好。