我们起首来看一下overflow属性的值有哪些?
overflow 属性规定当内容溢出元素框时发作的事变。
overflow有以下四个属性值
visible:初始值,内容不会被修剪,会呈如今元素框以外。
scroll:内容会被修剪,然则浏览器会显现转动条以便检察其他的内容。
hidden:内容会被修剪,而且其他内容是不可见的。
auto:假如内容被修剪,则浏览器会显现转动条以便检察其他的内容。
下面我们来仔细说一说overflow属性的这四个值
我们来看仔细的示例
代码以下
HTML代码
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>CSS overflow</title> <link rel="stylesheet" type="text/css" href="sample.css"> </head> <body> <div class="hid"> <p> The European languages are members of the same family. Their separate existence is a myth. For science, music, sport, etc, Europe uses the same vocabulary. The languages only differ in their grammar, their pronunciation and their most common words. Everyone realizes why a new common language would be desirable: one could refuse to pay expensive translators. </p> </div> <br> <div class="scr"> <p> The European languages are members of the same family. Their separate existence is a myth. For science, music, sport, etc, Europe uses the same vocabulary. The languages only differ in their grammar, their pronunciation and their most common words. Everyone realizes why a new common language would be desirable: one could refuse to pay expensive translators. </p> </div> <br> <div class="vis"> <p> The European languages are members of the same family. Their separate existence is a myth. For science, music, sport, etc, Europe uses the same vocabulary. The languages only differ in their grammar, their pronunciation and their most common words. Everyone realizes why a new common language would be desirable: one could refuse to pay expensive translators. </p> </div> </body> </html>
CSS代码
/*hidden*/ div.hid{ width: 200px; height: 100px; overflow: hidden; background-color: #FF9999; } /*scroll*/ div.scr{ width: 200px; height: 100px; overflow: scroll; background-color: #99FF99; } /*visible*/ div.vis{ width: 200px; height: 100px; overflow: visible; background-color: #9999FF; }
在浏览器上显现以下结果
当overflow的属性值是hidden时,结果以下
在hidden的情况下,不会显现出剩下的部份,也不能转动显现剩下的内容。
当overflow的属性值是scroll时,结果以下
在scroll的情况下,没有显现的内容能够转动。默许的情况下,笔墨在横向上会折回,垂直方向显现转动栏。
在css中设置white-space : nowrap(不自动转业的意义),也能够向横向转动。
CSS代码
div.scr{ width: 200px; height: 100px; white-space:nowrap; overflow: scroll; background-color: #99FF99; }
结果以下
别的,也能够运用overflow-x和overflow-y属性对垂直和横向的转动条的显现举行更加仔细的设置。
当overflow的属性值是visible时,结果以下
visible的情况下,从盒子中溢出显现。紫色的部份是div盒子。默许的情况下,笔墨在div的横向width中被折回,并在纵向方向上显现。
这个也和scroll属性值一样,在css中设置white-space : nowrap,也能够横向转动。
别的,假如不设置盒子的高度,就会自动转变盒子的高度。
div.vis{ width: 200px; /* height: 100px; */ overflow: visible; background-color: #9999FF; }
结果以下
末了,我们来看看当overflow属性值是auto时的仔细情况
HTML代码
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>CSS overflow</title> <link rel="stylesheet" type="text/css" href="sample.css"> </head> <body> <div class="aut"> <p> The European languages are members of the same family. Their separate existence is a myth. For science, music, sport, etc, Europe uses the same vocabulary. The languages only differ in their grammar, their pronunciation and their most common words. Everyone realizes why a new common language would be desirable: one could refuse to pay expensive translators. </p> </div> </body> </html>
CSS代码
div.aut{ width: 200px; height: 100px; overflow: auto; background-color: red; }
在浏览器上运转的结果和scroll类似
以上就是CSS中overflow属性怎样运用的仔细内容,更多请关注ki4网别的相干文章!