css中垂直水平居中的方式有哪些 CSS之垂直水平居中的背后
最开始,我想说,这个体系有点大,我写的并不好。就当作是一个思路吧,虽然这个思路有点乱。几乎每一个实现方案的背后都是该属性及其组合的原理,每一个都要剖析其规范细节的话,这篇文章绝不会是这样的篇幅,所以每
顺晟科技
2022-10-15 13:11:01
277
父布局div添加css:
position: relative;
子布局div添加css:
position: absolute;
bottom: 0;
left: 50%;
transform: translate(-50%, -50%);
代码如下:
<div style="min-height: 360px;position:relative;">
<div
style="
position: absolute;
bottom: 0;
left: 50%;
transform: translate(-50%, -50%); ">
</div>
<div>
水平居中
.hor_center {
margin: 0 auto;
}
水平垂直居中
<div class="content"></div>
.content {
width: 360px;
height: 240px;
}
.ver_hor_center {
position: absolute;
top: 50%;
left: 50%;
margin-left: -180px; /*要居中的div的宽度的一半*/
margin-top: -120px; /*要居中的div的高度的一半*/
}
div置于底部(footer),始终固定在页面底部
.bottom_footer {
position: fixed; /* or前面的是absolute就可以用 */
bottom: 0px;
}
作者:曌敏郡主
链接:https://juejin.cn/post/688786...
来源:稀土掘金
19
2022-10
15
2022-10
15
2022-09
15
2022-09
14
2022-09
14
2022-09