我正在使用带有八个文本div的Bootstrap 3设置一个看似简单的布局,几乎相同的高度,但根据屏幕宽度,有些稍高一些。
我希望它们适合桌面上的三列,并缩小到较小屏幕上的两列。
我尝试过什么
将每个div设置为col-xs-6和col-md-4。但是,在桌面上,div的大小会导致某些“单元格”出现空白。
在.row
中包装每组三个div,修复了桌面上的问题但在移动设备上添加了新问题。 (见下面的代码)
添加一个clear-md的clearfix div,但这并不能解决问题。
如何在桌面上的三个偶数列和移动设备上的两个偶数列(没有间隙)上显示以下标记?
<div class="row">
<div class="col-xs-6 col-md-4">
<h4><a href="#bond">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#buffa">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#ebert">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-md-4">
<h4><a href="#gale">text text</a></h4>
<p class="subtitle">Chief Accounting Officer</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#kleinman">text text</a></h4>
<p class="subtitle">General Counsel & Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#scarpati">text text</a></h4>
<p class="subtitle">Chief Compliance Officer</p>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-md-4">
<h4><a href="#selinger">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#tareke">text text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
</div>
答案 0 :(得分:1)
行类用于创建列组,但实际上并不需要。你可以摆脱它来实现你想要的外观。
<强> BOOTPLY 强>
<强> HTML 强>:
<div class="col-xs-6 col-md-4">
<h4><a href="#bond">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#buffa">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#ebert">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#gale">text text</a></h4>
<p class="subtitle">Chief Accounting Officer</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#kleinman">text text</a></h4>
<p class="subtitle">General Counsel & Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#scarpati">text text</a></h4>
<p class="subtitle">Chief Compliance Officer</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#selinger">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#tareke">text text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-xs-6 col-md-4">
<h4><a href="#bond">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#buffa">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#ebert">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#gale">text text</a></h4>
<p class="subtitle">Chief Accounting Officer</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#kleinman">text text</a></h4>
<p class="subtitle">General Counsel & Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#scarpati">text text</a></h4>
<p class="subtitle">Chief Compliance Officer</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#selinger">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#tareke">text text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
答案 1 :(得分:0)
@import url('http://getbootstrap.com/dist/css/bootstrap.min.css');
@media (max-width: 1023px) {
.col-xs-6 {
width: 50%;
}
}
&#13;
<div class="col-xs-6 col-md-4">
<h4><a href="#bond">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#buffa">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#ebert">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#gale">text text</a></h4>
<p class="subtitle">Chief Accounting Officer</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#kleinman">text text</a></h4>
<p class="subtitle">General Counsel & Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#scarpati">text text</a></h4>
<p class="subtitle">Chief Compliance Officer</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#selinger">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#tareke">text text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
&#13;
答案 2 :(得分:0)
妮可j。 Patten 看一下 Fiddle ,看看是否适合您...在这里寻找您的目标。
我将旧代码留在顶部,新代码显示在底部
在顶部显示了两个帽子,下半部分它们都很好地排列
这也可以很好地调整大小。
由于字体大小是文本在非常小的屏幕尺寸上堆叠的方式...(&lt; 320px)我使用媒体断点来帮助这里的几个类。
看看是否有帮助。
<!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">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>Starter Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<style>
body {
padding-top: 50px;
}
.space {
margin-top: 5%;
margin-bottom: 5%;
}
.space-1 {
margin-top: 5%;
height:10px;
margin-bottom: 5%;
background-color: blueviolet
}
.info {
height:90px;
margin-top: 2%;
margin-bottom:2%;
}
@media(max-width:320px) {
.info {
height:70px;
margin-top: 1%;
margin-bottom:1%;
}
p {
font-size: .8em;
}
h4 {
font-size: 1.0em;
}
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top ">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand " href="#">Project name</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container col-lg-12 space"></div>
<div class="container">
<div class="row">
<div class="col-xs-6 col-md-4">
<h4><a href="#bond">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#buffa">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#ebert">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-md-4">
<h4><a href="#gale">text text</a></h4>
<p class="subtitle">Chief Accounting Officer</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#kleinman">text text</a></h4>
<p class="subtitle">General Counsel & Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#scarpati">text text</a></h4>
<p class="subtitle">Chief Compliance Officer</p>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-md-4">
<h4><a href="#selinger">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4">
<h4><a href="#tareke">text text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
</div>
</div> <!--end container-->
<div class="container col-lg-12 space-1"></div>
<div class="container">
<div class="col-xs-6 col-md-4 info">
<h4><a href="#bond">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4 info">
<h4><a href="#buffa">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4 info">
<h4><a href="#ebert">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4 info">
<h4><a href="#gale">text text</a></h4>
<p class="subtitle">Chief Accounting Officer</p>
</div>
<div class="col-xs-6 col-md-4 info">
<h4><a href="#kleinman">text text</a></h4>
<p class="subtitle">General Counsel & Managing Director</p>
</div>
<div class="col-xs-6 col-md-4 info">
<h4><a href="#scarpati">text text</a></h4>
<p class="subtitle">Chief Compliance Officer</p>
</div>
<div class="col-xs-6 col-md-4 info">
<h4><a href="#selinger">text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
<div class="col-xs-6 col-md-4 info">
<h4><a href="#tareke">text text text</a></h4>
<p class="subtitle">Managing Director</p>
</div>
</div> <!--end container-->
<div class="container col-lg-12 space-1"></div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</body>
</html>
&#13;