欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

css中常用的幾種居中方法介紹

本篇內(nèi)容主要講解“css中常用的幾種居中方法介紹”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“css中常用的幾種居中方法介紹”吧!

在聶拉木等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作按需策劃設(shè)計(jì),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),全網(wǎng)營銷推廣,成都外貿(mào)網(wǎng)站建設(shè),聶拉木網(wǎng)站建設(shè)費(fèi)用合理。

今天我們就細(xì)數(shù)一下幾種方法:

1,使用position:absolute,設(shè)置left、top、margin-left、margin-top的屬性

CSS Code復(fù)制內(nèi)容到剪貼板

  1. .one{   

  2.            position:absolute;   

  3.            width:200px;   

  4.            height:200px;   

  5.            top:50%;   

  6.            left:50%;   

  7.            margin-top:-100px;   

  8.            margin-left:-100px;   

  9.            background:red;    

  10. }  

這種方法基本瀏覽器都能夠兼容,不足之處就是需要固定寬高。

2,使用position:fixed,同樣設(shè)置left、top、margin-left、margin-top的屬性

CSS Code復(fù)制內(nèi)容到剪貼板

  1. .two{   

  2.             position:fixed;   

  3.             width:180px;   

  4.             height:180px;   

  5.             top:50%;   

  6.             left:50%;   

  7.             margin-top:-90px;   

  8.             margin-left:-90px;   

  9.             background:orange;   

  10. }  

大家都知道的position:fixed,IE是不支持這個(gè)屬性的

3,利用position:fixed屬性,margin:auto這個(gè)必須不要忘記了。

CSS Code復(fù)制內(nèi)容到剪貼板

  1. .three{   

  2.             position:fixed;   

  3.             width:160px;   

  4.             height:160px;   

  5.             top:0;   

  6.             rightright:0;   

  7.             bottombottom:0;   

  8.             left:0;   

  9.             margin:auto;   

  10.             background:pink;   

  11. }  

4,利用position:absolute屬性,設(shè)置top/bottom/right/left

CSS Code復(fù)制內(nèi)容到剪貼板

  1. .four{   

  2.             position:absolute;   

  3.             width:140px;   

  4.             height:140px;   

  5.             top:0;   

  6.             rightright:0;   

  7.             bottombottom:0;   

  8.             left:0;   

  9.             margin:auto;   

  10.             background:black;   

  11. }  

5,利用display:table-cell屬性使內(nèi)容垂直居中

CSS Code復(fù)制內(nèi)容到剪貼板

  1. .five{   

  2.             display:table-cell;   

  3.             vertical-align:middle;   

  4.             text-align:center;   

  5.             width:120px;   

  6.             height:120px;   

  7.             background:purple;   

  8. }  

6,最簡單的一種使行內(nèi)元素居中的方法,使用line-height屬性

CSS Code復(fù)制內(nèi)容到剪貼板

  1. .six{   

  2.             width:100px;   

  3.             height:100px;   

  4.             line-height:100px;   

  5.             text-align:center;   

  6.             background:gray;   

  7.  }  

這種方法也很實(shí)用,比如使文字垂直居中對齊

7,使用css3的display:-webkit-box屬性,再設(shè)置-webkit-box-pack:center/-webkit-box-align:center

CSS Code復(fù)制內(nèi)容到剪貼板

  1. .seven{   

  2.             width:90px;   

  3.             height:90px;   

  4.             display:-webkit-box;   

  5.             -webkit-box-pack:center;   

  6.             -webkit-box-align:center;   

  7.             background:yellow;   

  8.             color:black;   

  9. }  

8,使用css3的新屬性transform:translate(x,y)屬性

CSS Code復(fù)制內(nèi)容到剪貼板

  1. .eight{   

  2.             position:absolute;   

  3.             width:80px;   

  4.             height:80px;   

  5.             top:50%;   

  6.             left:50%;   

  7.             transform:translate(-50%,-50%);   

  8.             -webkit-transform:translate(-50%,-50%);   

  9.             -moz-transform:translate(-50%,-50%);   

  10.             -ms-transform:translate(-50%,-50%);   

  11.             background:green;   

  12. }  

這個(gè)方法可以不需要設(shè)定固定的寬高,在移動(dòng)端用的會(huì)比較多,在移動(dòng)端css3兼容的比較好

9、最高大上的一種,使用:before元素

CSS Code復(fù)制內(nèi)容到剪貼板

  1. .nine{   

  2.             position:fixed;   

  3.             display:block;   

  4.             top:0;   

  5.             rightright:0;   

  6.             bottombottom:0;   

  7.             left:0;   

  8.             text-align:center;   

  9.             background:rgba(0,0,0,.5);   

  10. }   

  11. .nine:before{   

  12.             content:'';   

  13.             display:inline-block;   

  14.             vertical-align:middle;   

  15.             height:100%;   

  16. }   

  17.  .nine .content{   

  18.             display:inline-block;   

  19.             vertical-align:middle;   

  20.             width:60px;   

  21.             height:60px;   

  22.             line-height:60px;   

  23.             color:red;   

  24.             background:yellow;   

  25. }  

到此,相信大家對“css中常用的幾種居中方法介紹”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

標(biāo)題名稱:css中常用的幾種居中方法介紹
標(biāo)題路徑:http://www.chinadenli.net/article24/piijje.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)網(wǎng)站維護(hù)定制開發(fā)企業(yè)建站外貿(mào)建站網(wǎng)站導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化