我正试图将列的内容居中。看起来对我没用啊。这是我的HTML:
<div class="row">
<div class="col-xs-1 center-block">
<span>aaaaaaaaaaaaaaaaaaaaaaaaaaa</span>
</div>
</div>
JSFiddle演示
我正试图将列的内容居中。看起来对我没用啊。这是我的HTML:
<div class="row">
<div class="col-xs-1 center-block">
<span>aaaaaaaaaaaaaaaaaaaaaaaaaaa</span>
</div>
</div>
JSFiddle演示
当前回答
col- gl -4 col-md-6
1. col-lg-4 ≥ 1200px (popular 1366, 1600, 1920+)
2. col-md-6 ≥ 970px (popular 1024, 1200)
3. col-sm-8 ≥ 768px (popular 800, 768)
4. col-11 set default smaller devices for gutter (popular 600,480,414,375,360,312)
5. mx-auto = always block center
其他回答
没必要把事情复杂化。使用Bootstrap 4,您可以简单地使用边缘自动类my-auto在列内水平对齐项
<div class="col-md-6 my-auto">
<h3>Lorem ipsum.</h3>
</div>
Bootstrap 4/Bootstrap 5,水平和垂直对齐内容使用伸缩盒
<div class="page-hero d-flex align-items-center justify-content-center">
<h1>Some text </h1>
</div>
使用引导类align-items-center和justify-content-center
.page-hero { 身高:200 px; 背景颜色:灰色; } <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="匿名"> <div class="page-hero - d-flex align-items-center - align- content-center"> <h1>一些文本</h1> < / div >
这是一种简单的方法。
<div class="row">
<div class="col-md-6 mx-auto">
<p>My text</p>
</div>
</div>
数字6控制列的宽度。
col- gl -4 col-md-6
1. col-lg-4 ≥ 1200px (popular 1366, 1600, 1920+)
2. col-md-6 ≥ 970px (popular 1024, 1200)
3. col-sm-8 ≥ 768px (popular 800, 768)
4. col-11 set default smaller devices for gutter (popular 600,480,414,375,360,312)
5. mx-auto = always block center
//add this to your css
.myClass{
margin 0 auto;
}
// add the class to the span tag( could add it to the div and not using a span
// at all
<div class="row">
<div class="col-xs-1 center-block">
<span class="myClass">aaaaaaaaaaaaaaaaaaaaaaaaaaa</span>
</div>
</div>