Twitter bootstrap Html元素未与flex center垂直居中
那是我的小提琴: 为什么类为“垂直对齐”的html元素没有垂直居中Twitter bootstrap Html元素未与flex center垂直居中,twitter-bootstrap,css,Twitter Bootstrap,Css,那是我的小提琴: 为什么类为“垂直对齐”的html元素没有垂直居中 <div class="container"> <div class="row"> <div style="background:green;" class="col-xs-4"> <h3 class="text-center">Type 1</h3>
<div class="container">
<div class="row">
<div style="background:green;" class="col-xs-4">
<h3 class="text-center">Type 1</h3>
</div>
<div style="background:red;" class="col-xs-4">
<h3 class="text-center vertical-align">Type 2</h3>
</div>
<div style="background:blue;" class="col-xs-4">
<h3 class="text-center">Type 3</h3>
</div>
</div>
</div>
.vertical-align {
display: ms-flex;
display: flex;
align-items: center;
}
类型1
类型2
类型3
.垂直对齐{
显示器:ms flex;
显示器:flex;
对齐项目:居中;
}
只需添加调整内容:中心到您的代码:
.vertical-align {
display: ms-flex;
display: flex;
align-items: center;
justify-content: center;
}
我想这取决于你在这里想要实现什么<代码>对齐项目垂直对齐。其中,as
justify content
是水平对齐的
看。我已经给出了
高度,以说明它是垂直居中的 这不就是文本居中对齐吗?他要求的是垂直对齐,而不是水平对齐。你的h3
上有页边距顶部:20px
和页边距底部:10px
。也许来自引导。这将阻止中间对齐。此外,您为什么要在h3
上使用flex?孩子们在哪里?它会弯曲什么?