综合百科

CSS中overflow指的是什么意思

在CSS中,overflow是“溢出”的意思,该属性规定当内容溢出元素框时发生的事情,设置内容是否会被修剪,溢出部分是否会被隐藏;例如当属性值设置为“visible”则内容不会被修剪,为“hidden”则内容会被修剪并且其余内容是不可见的。

本教程操作环境:windows7系统、CSS3&&HTML5版、Dell G3电脑。

在CSS中,overflow是“溢出”的意思,该属性规定当内容溢出元素框时发生的事情。

overflow属性支持4个属性,可设置当内容溢出元素框时的4种理方式:

  • visible 默认值。内容不会被修剪,会呈现在元素框之外。

  • hidden 内容会被修剪,并且其余内容是不可见的。

  • scroll 内容会被修剪,但是浏览器会显示滚动条以便查看其余的内容。

  • auto 如果内容被修剪,则浏览器会显示滚动条以便查看其余的内容。

<!DOCTYPEhtml><html><head><metacharset="utf-8"><style>p.ex1{background-color:lightblue;width:150px;height:110px;overflow:scroll;}p.ex2{background-color:lightblue;width:150px;height:110px;overflow:hidden;}p.ex3{background-color:lightblue;width:150px;height:110px;overflow:auto;}p.ex4{background-color:lightblue;width:150px;height:110px;overflow:visible;}</style></head><body><h2>overflow属性</h2><p>如果元素中的内容超出了给定的宽度和高度属性,overflow属性可以确定是否显示滚动条等行为。</p><h3>overflow:scroll:</h3><pclass="ex1">测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!</p><h3>overflow:hidden:</h3><pclass="ex2">测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!</p><h3>overflow:auto:</h3><pclass="ex3">测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!</p><h3>overflow:visible(默认):</h3><pclass="ex4">测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!</p></body></html>