比如某聘网首页,网页整体居中显示,中间横屏轮播图宽2000多像素,但是浏览器却不会显示滑动条,我做了一下只要有个div宽度超出浏览器显示范围就会自动出现左右滑块,要怎么做才能使其不会出现左右滑块?
海报宽设置成百分百,内容页面宽设置一个固定值,就是默认显示的值,max-width设置成100%,也就是你怎么放大最多也只能到百分百
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
#box1 {
background-color: aqua;
width: 800px;
max-width: 100%;
height: 200%;
margin: 0 auto;
}
#box2 {
background-color: red;
width: 100%;
height: 50vh;
}
</style>
<body>
<div id="box2">
<div id="box1">
</div>
</div>
</body>
<script>
</script>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<style>
.box {
display: flex;
flex-direction: column;
/* flex设置内容图片居中 */
justify-content: center;
align-items: center;
/* 禁止左右滑动 */
overflow-x: hidden;
}
img {
/*设置固定宽度*/
width: 1920px;
height: 290px;
}
.d1 {
width: 90%;
text-align: center;
background-color: aquamarine;
}
</style>
</head>
<body>
<div class="box">
<div class="d1">1</div>
<img src="https://image0.lietou-static.com/img/61074bfb58bdc324d6ca9a9f05u.jpg">
<div class="d1">2</div>
</div>
</body>
</html>
如果只是需要隐藏滚动条 但是又希望滚动 可以利用css隐藏滚动条
body::-webkit-scrollbar {
width: 0 !important
}
body {
/*IE 10+ */
-ms-overflow-style: none;
/*Firefox */
overflow: -moz-scrollbars-none;
}