有没有可能做col
这个问题在这里已经有了答案:
是的,但为此,您需要覆盖Bootstrap列的样式。 默认情况下,Bootstrap的列被设置为float: left
。 我们需要用display: inline-block
替换float
,然后我们可以用text-align: center
轻松地将它们放在text-align: center
。
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
.center-align .row {
letter-spacing: -4px;
text-align: center;
font-size: 0;
}
.center-align [class*='col-md'] {
display: inline-block;
vertical-align: top;
letter-spacing: 0;
text-align: left;
font-size: 16px;
float: none;
}
<div class="container center-align">
<div class="row">
<div class="col-md-3">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifend imperdiet elit vel pretium. Donec auctor urna ut dui imperdiet ullamcorper.</p>
</div>
<div class="col-md-3">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifend imperdiet elit vel pretium. Donec auctor urna ut dui imperdiet ullamcorper.</p>
</div>
<div class="col-md-3">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifend imperdiet elit vel pretium. Donec auctor urna ut dui imperdiet ullamcorper.</p>
</div>
</div>
</div>
是的,可以将CSS应用于父div。 在你的div div class =“row”like style =“text-align:center;”
更新HTML
<div class="container">
<div class="row col-md-offset-1">
<div class="col-md-3">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifend imperdiet elit vel pretium. Donec auctor urna ut dui imperdiet ullamcorper.</p>
</div>
<div class="col-md-3">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifend imperdiet elit vel pretium. Donec auctor urna ut dui imperdiet ullamcorper.</p>
</div>
<div class="col-md-3">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifend imperdiet elit vel pretium. Donec auctor urna ut dui imperdiet ullamcorper.</p>
</div>
</div>
</div>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<style>
body {
margin-top: 50px;
}
</style>
<body>
<div class="container">
<div class="row col-md-offset-1">
<div class="col-md-3">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifend imperdiet elit vel pretium. Donec auctor urna ut dui imperdiet ullamcorper.</p>
</div>
<div class="col-md-3">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifend imperdiet elit vel pretium. Donec auctor urna ut dui imperdiet ullamcorper.</p>
</div>
<div class="col-md-3">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifend imperdiet elit vel pretium. Donec auctor urna ut dui imperdiet ullamcorper.</p>
</div>
</div>
</div>
</body>
</html>
链接地址: http://www.djcxy.com/p/75901.html