我的页面上有一个水平滚动,但我不明白为什么:/我尝试使用margin和padding修复它,但是没有任何效果。你知道问题可能是什么吗?我认为在添加视差效果之前我没有遇到这个问题(我只有叠加菜单div和按钮的自举行)但删除了所有的视差代码并没有解决这个问题。
/*------------BODY------------*/
body {
position: relative;
padding: 0%;
margin: 0;
font-family: 'Lato', sans-serif;
background-color: black;
width: 100%;
}
body,
html {
height: 100%;
margin: 0;
padding: 0;
}
.parallax {
/* The image used */
background-image: url('img_parallax.jpg');
/* Full height */
height: 100%;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
margin: 0;
padding: 0;
}
.parallax2 {
/* The image used */
background-image: url('img_parallax.jpg');
/* Full height */
height: 100%;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
margin: 0;
padding: 0;
}
/* Turn off parallax scrolling for tablets and phones. Increase the pixels if needed */
@media only screen and (max-device-width: 1024px) {
.parallax {
background-attachment: scroll;
}
}
/*------------MENU------------*/
.overlay {
height: 0%;
width: 100%;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0, 0, 0);
background-color: rgba(255, 255, 255, 0.9);
overflow-y: hidden;
transition: 0.5s;
}
.overlay-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
.overlay a {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
}
.overlay a:hover,
.overlay a:focus {
color: #f1f1f1;
}
.overlay .closebtn {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}
@media screen and (max-height: 450px) {
.overlay {
overflow-y: auto;
}
.overlay a {
font-size: 20px
}
.overlay .closebtn {
font-size: 40px;
top: 15px;
right: 35px;
}
}
.menubutton {
cursor: pointer;
}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="parallax">
<div id="myNav" class="overlay">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<div class="overlay-content">
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Clients</a>
<a href="#">Contact</a>
</div>
</div>
<div id="menucontainer">
<div class="row">
<div class="col-sm-4"></div>
<div class="col-sm-4">
<center>
<div class="menubutton" onclick="openNav()">menubutton</div>
</center>
</div>
<div class="col-sm-4"></div>
</div>
</div>
</div>
<div class="parallax2">
PARALLAX2
</div>
<div class="parallax"></div>
&#13;
答案 0 :(得分:3)
Bootstrap .row
具有负边距,将其包装到.container
或.container-fluid
。
<div class=container-fluid><div class="row"></div></div>
/*------------BODY------------*/
body {
position: relative;
padding: 0%;
margin: 0;
font-family: 'Lato', sans-serif;
background-color: black;
width: 100%;
}
body,
html {
height: 100%;
margin: 0;
padding: 0;
}
.parallax {
/* The image used */
background-image: url('img_parallax.jpg');
/* Full height */
height: 100%;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
margin: 0;
padding: 0;
}
.parallax2 {
/* The image used */
background-image: url('img_parallax.jpg');
/* Full height */
height: 100%;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
margin: 0;
padding: 0;
}
/* Turn off parallax scrolling for tablets and phones. Increase the pixels if needed */
@media only screen and (max-device-width: 1024px) {
.parallax {
background-attachment: scroll;
}
}
/*------------MENU------------*/
.overlay {
height: 0%;
width: 100%;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0, 0, 0);
background-color: rgba(255, 255, 255, 0.9);
overflow-y: hidden;
transition: 0.5s;
}
.overlay-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
.overlay a {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
}
.overlay a:hover,
.overlay a:focus {
color: #f1f1f1;
}
.overlay .closebtn {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}
@media screen and (max-height: 450px) {
.overlay {
overflow-y: auto;
}
.overlay a {
font-size: 20px
}
.overlay .closebtn {
font-size: 40px;
top: 15px;
right: 35px;
}
}
.menubutton {
cursor: pointer;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="parallax">
<div id="myNav" class="overlay">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<div class="overlay-content">
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Clients</a>
<a href="#">Contact</a>
</div>
</div>
<div id="menucontainer">
<div class=container-fluid>
<div class="row">
<div class="col-sm-4"></div>
<div class="col-sm-4">
<center>
<div class="menubutton" onclick="openNav()">menubutton</center>
</div>
<div class="col-sm-4"></div>
</div>
</div>
</div>
</div>
<div class="parallax2">
PARALLAX2
</div>
<div class="parallax"></div>
行必须放在.container(固定宽度)或 .container-fluid(全宽),用于正确对齐和填充。 - (Bootstrap简介)
<强> More Info 强>
答案 1 :(得分:0)
将“container”或“container-fluid”类赋予div id =“menucontainer”。 “行”类有负边际。