gpt4 book ai didi

html - Bootstrap - 将 DIV 对齐到顶部、中间和底部

转载 作者:太空狗 更新时间:2023-10-29 15:40:42 30 4
gpt4 key购买 nike

我需要在一个容器 DIV 中包含三个 DIV,它们都水平居中。第一个需要与容器的垂直顶部对齐,第二个需要与垂直中心对齐,第三个需要与垂直底部对齐。这是 an answer垂直放置一个 div,但不处理其他元素。另一个答案here ,但是如何将需要垂直对齐的 DIV 添加到顶部和底部?

这是 HTML:

<div class="carousel-caption"> <!-- outer container; all items horizontally centered -->
<div class="row align-top"> <!-- align this DIV to top -->
<h1 class="col-sm-12">Top DIV</h1>
</div>
<div class="row align-vertical-center"> <!-- align this DIV to center -->
<div class="col-sm-12 ">Middle DIV</div>
</div>
<div class="row align-vertical-bottom">
<div class="align-vertical-bottom">Bottom DIV</div>
</div>
</div>

最佳答案

对于这个 HTML:

<div class="container">
<div class="carousel-caption"> <!-- outer container; all items horizontally centered -->
<div class="row vtop"> <!-- align this DIV to top -->
<div class="col-sm-12">Top DIV</div>
</div>
<div class="row vcenter"> <!-- align this DIV to center -->
<div class="col-sm-12 ">Middle DIV</div>
</div>
<div class="row vbottom">
<div class="col-sm-12 vbottom">Bottom DIV</div>
</div>
</div>
</div>

这个 CSS:

.carousel-caption{
padding:0;
}

.vtop{
/*padding on parent fixes this*/
}

.vcenter{
position: relative;
top: 50%;
transform: translateY(-50%);
}

.vbottom{
position: relative;
top: 100%;
transform: translateY(-100%);
}

参见 this Bootply Demo

喂!

关于html - Bootstrap - 将 DIV 对齐到顶部、中间和底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29258382/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com