Is it possible to make col
This question already has an answer here:
Yes, but for this you need to override styling for Bootstrap's columns. By default Bootstrap's columns are styled as float: left
. We need to replace float
with display: inline-block
then we can make them in center easily with 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>
Yes it is possible, to apply css to parent div. In your case div with 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/75902.html
上一篇: 使用Bootstrap对列进行居中
下一篇: 有没有可能做col