关于前端:DIV在另一个DIV底部居中

4次阅读

共计 613 个字符,预计需要花费 2 分钟才能阅读完成。

父布局 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…
起源:稀土掘金

正文完
 0