我正在为我的老板设计一个简单的网站。我决定尝试使用bootstrap,并选择了版本4。所以我有一个非常好的模板结构,并注意到主要内容的行超出了容器div的边界。这是页面上唯一一行这样做。我尝试改变间距与边距或填充的任何一个/两个元素,它似乎没有改变任何东西。我还尝试过将主要内容包含在section标记中,因为其他两行包含在header/footer标记中,并且它们仍然在边界内。这也不起作用。我可能在这里遗漏了一些明显的东西。感谢您的帮助,我很感激。
我突出显示了容器只是为了显示它的边界框。我也有填充从它删除在这个截图中,这是同样的问题,无论哪种方式虽然。
<!doctype html>
<html lang="en">
<head>
<title>Air Technology West</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- fontawesome CDN embed -->
<script src="https://use.fontawesome.com/f13a1bd68c.js"></script>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
<!-- Header area -->
<header class="pt-3 px-3">
<div class="row">
<div class="col-md-6">
<a href="#"><img class="logo" src="img/logo1.png"></a>
</div>
<div class="col-md-6">
<ul class="contact-info">
<li class="ph-local"><i class="fa fa-phone fa-fw"></i> xxx-xxx-xxxx</li>
<li class="ph-fax"><span class="fnt-sm">Fax: </span><i class="fa fa-fax fa-fw"></i> xxx-xxx-xxxx</li>
</ul>
</div>
</div><!--END ROW-->
</header>
<nav class="navbar navbar-expand-md nav-main d-flex flex-row">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#nav-main-toggle" aria-controls="nav-main-toggle" aria-expanded="false" aria-label="Toggle navigation">
<span class="fa fa-bars fa-2x"></span><span class="btn-collapse"> MENU</span>
</button>
<div class="collapse navbar-collapse" id="nav-main-toggle">
<div class="nav navbar-nav mr-auto">
<p class="nav-item"><a class="nav-link px-3" href="#">Home</a></p>
<p class="nav-item"><a class="nav-link px-3" href="#">About Us</a></p>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Products</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Compressors</a>
<a class="dropdown-item" href="#">Spray Equipment</a>
<a class="dropdown-item" href="#">Parts & Accessories</a>
<a class="dropdown-item" href="#">All Major Products</a>
</div>
</li>
<p class="nav-item"><a class="nav-link px-3" href="#">Services</a></p>
<p class="nav-item"><a class="nav-link px-3" href="#">Contact Us</a></p>
</div>
</div>
</nav>
<!--===========END header area==============-->
<!--===========CAROUSEL area================-->
<div id="carousel-main" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carousel-main" data-slide-to="0" class="active"></li>
<li data-target="#carousel-main" data-slide-to="1"></li>
<li data-target="#carousel-main" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<a href="#"><img class="d-block w-100" src="img/headline_compressors.PNG" alt="First slide"></a>
</div>
<div class="carousel-item">
<a href="#"><img class="d-block w-100" src="img/headline_spray.PNG" alt="Second slide"></a>
</div>
<div class="carousel-item">
<a href="#"><img class="d-block w-100" src="http://via.placeholder.com/720x300" alt="Third slide"></a>
</div>
</div><!--END CAROUSEL INNER-->
<a class="carousel-control-prev" href="#carousel-main" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carousel-main" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<!--===========END carousel area============-->
<!--===========PAGE content==============-->
<section id="page-content">
<div class="row">
<aside class="col-md-3">
<div class="card mt-3">
<a href="#">
<img class="card-img-top" src="http://via.placeholder.com/200x200" alt="Card image cap">
<div class="card-body">
<p class="card-text">Service</p>
</div>
</a>
</div>
<div class="card mt-3">
<a href="#">
<img class="card-img-top" src="http://via.placeholder.com/200x200" alt="Card image cap">
<div class="card-body">
<p class="card-text">Products</p>
</div>
</a>
</div>
<div class="card mt-3">
<a href="#">
<img class="card-img-top" src="http://via.placeholder.com/200x200" alt="Card image cap">
<div class="card-body">
<p class="card-text">Parts & accessories</p>
</div>
</a>
</div>
</aside>
<article class="main col-md-9 col-sm-12 px-3 mt-3">
<p>This is the main content area</p>
</article>
</div><!--END ROW-->
</section><!--END PAGE CONTENT-->
<!--============END page content===============-->
<!--=============footer area===============-->
<footer class=" my-3 px-3">
<div class="row">
<div class="col-sm-6">
<h3 class="border-bottom">Quick links</h3>
<nav class="nav row nav-footer">
<a class="nav-link col-md-4 col-sm-6" href="#">Products</a>
<a class="nav-link col-md-4 col-sm-6" href="#">Services</a>
<a class="nav-link col-md-4 col-sm-6" href="#">About Us</a>
<a class="nav-link col-md-4 col-sm-6" href="#">Contact Info</a>
<a class="nav-link col-md-4 col-sm-6" href="#">Directons</a>
<a class="nav-link col-md-4 col-sm-6" href="#">Site Map</a>
</nav>
</div>
<div class="col-sm-6 contact-info">
<h3 class="border-bottom">Contact Info</h3>
<p class="ph-local"><i class="fa fa-phone fa-fw"></i> xxx-xxx-xxxx</p>
<p class="ph-fax"><span class="fnt-sm">Fax: </span><i class="fa fa-fax fa-fw"></i> xxx-xxx-xxxx</p>
<p class="address"><i class="fa fa-map-marker fa-fw"></i> ADDRESS</p>
</div>
</div><!--END ROW-->
</footer>
<!--==============END footer area================-->
</div><!--===============END CONTAINER===============-->
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
</body>
</html>
编辑:添加styles.css文件。
html{
font-family: verdana, helvetica, sans-serif !important;
}
nav a{
color: black;
list-style: none;
text-align: center;
text-transform: uppercase;
}
.nav .nav-link, .nav .dropdown-item {
color: black;
}
.dropdown-toggle{
color: black;
}
.nav a:hover{
border-bottom: 3px solid black;
margin-bottom: -3px;
}
.nav a:active{
background-color: grey;
color: white;
}
.navbar{
padding: .1rem;
}
.navbar-toggler{
margin-left:auto;
margin-right: auto;
}
/*********************3. LAYOUT********************/
#carousel-main{
position:relative;
}
.carousel-button-right{
position: absolute;
bottom: 2rem;
right: 25%;
}
.carousel-button-left{
position: absolute;
bottom: 2rem;
left: 25%;
}
.carousel-button-center{
position: absolute;
bottom: 30px;
right: 50%;
}
/*********************4. MODULES*******************/
/********4.1 HEADER *********/
.logo{
height: auto;
max-width: 100%;
}
.contact-info{
list-style: none;
text-align: right;
}
.fnt-sm{
font-size: .75rem;
}
.ph-local{
font-size: 1.75rem;
}
/********4.2 MAIN NAV********/
.btn-collapse{
font-size: 2.2rem;
font-weight: bold;
}
/********FOOTER********/
.border-bottom{
border-bottom: 1px solid black;
}
/*********************5. STATES********************/
/*********************6. THEME*********************/
body{
background-image: url("../img/escheresque_ste.png");
background-repeat: repeat;
}
header, footer, .navbar, .main{
background-color: white;
}
@media (max-width: 767px) {
header *{
text-align:center;
}
nav .nav-item{
text-align: center;
}
aside{
display: none;
}
}
@media (max-width: 575px) {
footer *{
text-align: center;
}
footer nav .nav-item{
text-align: center;
}
}
@media (min-width: 576px) {
footer.contact-info *{
text-align: right;
}
}
6条答案
按热度按时间mrzz3bfm1#
bootstrap中的.row提供的左右边距为-15px,请使用in-line style=“margin:自动”,你应该没事。
aside的默认左填充和右填充都是15,因此在您的情况下,应该将padding-left设置为0,以使内容适合网格。
gstyhher2#
将“no-gutters”类
class='row no-gutters'
添加到bootstrap 4行中也是一种消除边距和填充的好方法。在我们预定义的网格类中,列之间的分隔线可以用.no-gutters来删除,这将删除.row中的负边距和所有直接子列中的水平填充。
https://getbootstrap.com/docs/4.1/layout/grid/#no-gutters
gywdnpxw3#
使用类
mr-0
代替style="margin-right: 0"
,style="margin-right: 0"
是 Bootstrap 4路。tvmytwxo4#
将
mx-0
添加到溢出元素将解决您的问题。gpfsuwkq5#
考虑到上述答案,有时你需要编辑默认的CSS属性在您的项目。所以如果你想应用
no-gutters
或任何CSS属性,你可以简单地改变该属性的主CSS/SASS文件如下:这个黑客将删除所有行在您的项目中的无排水沟保证金!
j5fpnvbx6#
Bootstrap为行类添加了一个自动的水平间距,所以通过将水平间距(即边距)设置为0来覆盖它,就像;