css3 - 如何让div中的内容水平居中,垂直居中
怪我咯
怪我咯 2017-04-17 11:23:59
0
3
1071

将内容区域的样式设置成这样,可以解决,可是在编码的时候也会有很多问题。

.element {
    width: 60px; height: 40px;
    position: absolute; left: 0; top: 0; right: 0; bottom: 0;
    margin: auto;    /* 有了这个就自动居中了 */
    border:1px solid red;
}

有其他的方法吗

怪我咯
怪我咯

走同样的路,发现不同的人生

répondre à tous(3)
洪涛

首先get一个新方法;
我一般这样居中
.element {

width: 60px; height: 40px;
position: absolute;
left: 50%;
top: 50%;
transform:translate(-50%,-50%);
border:1px solid red;
}

小葫芦

你需要:CSS布局之-水平垂直居中

巴扎黑

看这里 http://f2e.souche.com/blog/jie-du-cssbu-ju-zhi-shui-ping-chui-zhi-ju-zhong/

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!