Html+Css

CSS overflow

2018-12-12  本文已影响10人  roy_pub

overflow

参数 说明
visible 不剪切,不添加滚动条
auto 超出显示滚动条,不超出不显示滚动条
hidden 不显示超过尺寸的内容,溢出隐藏
scroll 总是显示滚动条
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
       div {
           width: 200px;
           height: 200px;
           border: 1px solid orange;
       }
    </style>
</head>
<body>
    <div>
        Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World
    </div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
       div {
           width: 200px;
           height: 200px;
           border: 1px solid orange;
           overflow: hidden;
       }
    </style>
</head>
<body>
    <div>
        Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World
    </div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
       div {
           width: 200px;
           height: 200px;
           border: 1px solid orange;
           overflow: scroll;
       }
    </style>
</head>
<body>
    <div>
        Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World
    </div>
</body>
</html>

溢出部分显示省略号

首先强制一行内显示,再和overflow属性搭配使用。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            border: 1px solid orange;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
</head>
<body>
<div>
    Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World World Hello World Hello World
</div>
</body>
</html>
上一篇下一篇

猜你喜欢

热点阅读