新聞中心
這篇文章給大家分享的是有關(guān)css如何實(shí)現(xiàn)水平垂直居中的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧。
播州網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),播州網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為播州1000+提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的播州做網(wǎng)站的公司定做!
垂直居中的純css方法
一、基于position:absolute,(但是絕對(duì)定位,會(huì)脫離文檔流,對(duì)兄弟元素不友好)
1、position: absolute;top: 50%;left: 50%;margin-top: -50px;margin-left: -50px;
2、margin: auto;position: absolute;top: 0;right:0;bottom: 0;left: 0;
以上兩種div大小明確
3、transform:translate(-100px,-100px);position: absolute;top: 50%;left: 50%;
二、大小不明確
4、display:flex;justify-content:center;align-items:center;
5、display:table,(會(huì)破壞頁(yè)面整體布局)
.wrapper { height: 400px; width:600px; border: 2px solid pink; border-radius:10px; display:table; } .box { text-align:center; position:relative; display:table-cell; vertical-align:middle; background:#abcdef; }
adfagagafajkfhla
感謝各位的閱讀!關(guān)于css如何實(shí)現(xiàn)水平垂直居中就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
網(wǎng)站題目:css如何實(shí)現(xiàn)水平垂直居中
網(wǎng)站URL:http://fisionsoft.com.cn/article/ijisjh.html