您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

css实现隐藏滚动条的代码案例

2024/5/1 6:09:58发布24次查看
overflow 属性规定当内容溢出元素框时发生的事情
①visible           默认值。内容不会被修剪,会呈现在元素框之外。
②hidden          内容会被修剪,并且其余内容是不可见的。
③scroll            内容会被修剪,但是浏览器会显示滚动条以便查看其余的内容。
④auto              如果内容被修剪,则浏览器会显示滚动条以便查看其余的内容。
⑤inherit           规定应该从父元素继承 overflow 属性的值。
例子一:table做容器且【隐藏】滚动条
注意:{①table的dispaly设置为block,否则不会出现滚动条}
要先把table放到一个p中,p的长度和宽度要固定
如果只想垂直方向有滚动,可以设置外面p属性overflow-x: hidden;
例子:
<html lang="en"> <head> <meta charset="utf-8"> <title>滚动条</title> <style type="text/css"> *{margin: 0;padding: 0} .area{width: 300px;height: 600px;background-color: #bfefff; overflow-x: hidden;position: relative} .area table{display: block;width: 320px;height: 600px; background-color: #00d685;overflow-y: auto;} .area table tr td{height: 200px;width: 300px} </style> </head> <body> <p class="area"> <table> <tr><td>1</td></tr> <tr><td>2</td></tr> <tr><td>3</td></tr> <tr><td>4</td></tr> <tr><td>5</td></tr> <tr><td>6</td></tr> </table> </p> </body> </html>
这里注意修改table属性
例子二:
ul作容器,隐藏滚动条
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>滚动条</title> <style type="text/css"> *{margin: 0;padding: 0} .area{width: 300px;height: 600px;background-color: #bfefff; overflow-x: hidden; position: relative} .area ul{height: 100%;width: 320px;background-color: #00d685;list-style: none; overflow-x: hidden;overflow-y: auto} .area ul li{height: 200px;width: 100%;background-color: #cccccc} </style> </head> <body> <p class="area"> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> </ul> </p> </body> </html>
原理:在容器外面再嵌套一层 overflow:hidden 内部内容再限制尺寸和外部嵌套层一样,就变相隐藏了。
以上就是css实现隐藏滚动条的代码案例的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product