我试图将(在水平和垂直方向)居中的一个div(它是class="centered-column"
的一个)嵌套在一个弹性行下。
我尝试应用this answer和this css-tricks guide上提供的信息,但没有成功。
以下是代码:
span {
font-size: 20px;
}
.row {
display: -webkit-flex;
display: -ms-flexbox;
}
.col-md-8 {
background-color: lightblue;
}
.centered-column {
display: flex;
flex-direction: column;
justify-content: center;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col-md-4 text-center">
<div class="row">
<div class="col-md-12">
<span>Row number 1</span>
</div>
</div>
<div class="row">
<div class="col-md-12">
<span>Row number 2</span>
</div>
</div>
</div>
<div class="col-md-8">
<div class="centered-column">
<span>Some text<span>
</div>
</div>
</div>
我该怎么做才能使它工作(注意我必须使用Bootstrap 3)?
答案 0 :(得分:0)
正如@Temani afif评论的那样,唯一需要改变的是:
<div class="col-md-8 centered-column">
<span>Some text<span>
</div>
完整代码段:
span {
font-size: 20px;
}
.row {
display: -webkit-flex;
display: -ms-flexbox;
}
.col-md-8 {
background-color: lightblue;
}
.centered-column {
display: flex;
flex-direction: column;
justify-content: center;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col-md-4 text-center">
<div class="row">
<div class="col-md-12">
<span>Row number 1</span>
</div>
</div>
<div class="row">
<div class="col-md-12">
<span>Row number 2</span>
</div>
</div>
</div>
<div class="col-md-8 centered-column">
<span>Some text<span>
</div>
</div>