我正在创建一个具有全宽度布局的导航栏,我创建了容器流体类作为导航包装器,其中是行类,后面是列....据我所知,这是bootstrap的正确结构,但我左右两边都有一个边距。
这是我的HTML:
<div class="container-fluid">
<div class="row">
<div class="header">
<div class="col-sm-1">
<div class="header_category_icon">
</div>
</div>
<div class="col-sm-10">
</div>
<div class="col-sm-1">
<div class="header_search_icon">
</div>
</div>
</div>
</div>
</div>
这是我的CSS:
.header {
height:50px;
background-color:#222222;
}
.header_category_icon, .header_search_icon {
background-color:#575757;
height:50px;
}
感谢您的帮助
答案 0 :(得分:2)
请注意col-sm-*
应该是.row
的直接子女:
<div class="container-fluid header">
<div class="row">
<div class="col-sm-1">
...
工作示例:
.header>.row>[class^="col-"] {
border: 1px solid red;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<div class="container-fluid header">
<div class="row">
<div class="col-sm-12">
This is an example
</div>
</div>
</div>
&#13;
仔细看看Bootstrap示例。
答案 1 :(得分:0)
感谢您的帮助 - 共同的问题是col-XX-XX不是容器流体的孩子,也是header_category_icon&amp; amp; header_search_icon不需要子类,它们可以在col类中,如下所示:
<div class="container-fluid header">
<div class="row">
<div class="col-sm-1 header_category_icon">
</div>
<div class="col-sm-10">
</div>
<div class="col-sm-1 header_search_icon">
</div>
</div>
</div>