有时候需要页面某一部分(比如头部一张很长的图片)局部滚动,页面其他部分不跟着滚,实现方式如下:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
<style type="text/css" rel="stylesheet">
.box {
margin-left: 0px;
margin-right: 0px;
width: 100%;
height: auto;
overflow-x: scroll;
overflow-y: hidden;
}
</style>
<div class="box">
<img src="mf.jpg" style="max-height:350px;" />
</div>
</body>
</html>
width: 100%;限定宽度为屏幕宽度
overflow-x: scroll;设置div里面内容超过时,可以水平滚动
纵向:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
<style type="text/css" rel="stylesheet">
.box2 {
width: 100%;
height: 20px;
background-color: antiquewhite;
line-height: 50px;
overflow-y: scroll;
}
</style>
<div class="box2">
<div>fdasf</div>
<div>1111</div>
</div>
</body>
</html>
网友评论