日本一卡精品视频免费丨国产午夜片无码区在线播放丨国产精品成人久久久久久久丨国产亚洲日韩av在线播放不卡丨亚洲日韩av无码

DIV里css如何水平居中和垂直居中

2016/8/26 8:37:10   閱讀:1533    發(fā)布者:1533

水平居中:
內(nèi)聯(lián)元素:text-align:center;相對于父級居中顯示
塊級元素:margin:0 auto;但是需要同時width,否則無法看到效果
多個塊級元素居中:在此想要探討一下display:inline-block;和display:flex;
方法1:在父級上設(shè)置text-align:center;在元素上設(shè)置:display:inline-block;同時為了使文字向左顯示,
設(shè)置了text-align:left;在瀏覽器中的顯示為,子元素高度自適應(yīng),底部對齊。
方法2:在子元素上設(shè)置display:center;justify-content:center;子元素的高度一致,與元素中內(nèi)容最多的高度相同。
二種方法在谷歌,火狐,360均兼容,但是第2種方法在IE10中不兼容,之前的IE版本可想也是不兼容的。
當(dāng)然在此也要處理由于浮動導(dǎo)致離層,父級背景顏色加不上去的問題。

 1 <main class="inline-block-center">  
 2   <div>  
 3     I’m an element that is block-like with my siblings and we’re centered in a row.  
 4 </div>  
 5   <div>  
 6     I’m an element that is block-like with my siblings and we’re centered in a row.  
I have more content in me than my siblings do.  
 7 </div>  
 8   <div>  
 9     I’m an element that is block-like with my siblings and we’re centered in a row.  
10 </div>  
11 </main>
 1 <main class="flex-center">  
 2   <div>  
 3     I’m an element that is block-like with my siblings and we’re centered in a row.  
 4 </div>  
 5   <div>  
 6     I’m an element that is block-like with my siblings and we’re centered in a row.  
I have more content in me than my siblings do.  
 7 </div>  
 8   <div>  
 9     I’m an element that is block-like with my siblings and we’re centered in a row.  
10 </div>  
11 </main>

 

 1 body {  
 2   background: #f06d06;  
 3   font-size: 80%;  
 4 }  
 5 main {  
 6   background: white;  
 7   margin: 20px 0;  
 8   padding: 10px;  
 9 }  
10 main div {  
11   background: black;  
12   color: white;  
13   padding: 15px;  
14   max-width: 125px;  
15   margin: 5px;  
16 }  
17 .inline-block-center {  
18   text-align: center;  
19 }  
20 .inline-block-center div {  
21   display: inline-block;  
22   text-align: left;  
23 }  
24 .flex-center {  
25   display: flex;  
26   justify-content: center;  
27 }

垂直居中:

方法1:設(shè)置padding-top和padding-bottom的值相等
方法2:設(shè)置height和line-height的值相等
方法3:固定高度可以有一種處理方式position:absolute;top:50%;height:100px;margin-top:-50px;
如果高度不固定,也可以使用js動態(tài)獲取高度來。
還有css3的一些屬性,考慮到兼容性問題不在敘述。

主站蜘蛛池模板: 大白肥妇bbvbbw高潮| 国产精品夜间视频香蕉| 国产成人精品午夜2022| www国产亚洲精品久久网站| 久久成年片色大黄全免费网站| 同性情a三级a三级a三级| 国产精品久久久久久久久免费| 亚洲精品久久久久久中文传媒 | 影音先锋女人av鲁色资源网久久 | 免费人成再在线观看网站| 久久99国产精品成人| 天天做天天摸天天爽欧美一区| 色yeye香蕉凹凸视频在线观看| 91日韩在线视频| 亚洲成人av中文字幕| 久久婷婷五月综合色国产| 性一交一乱一色一免费无遮挡| 国产精品国产三级国产av中文| 超黄网站在线观看| 亚洲春色av无码专区在线播放| 久久午夜电影网| 久久爱影视i| 欧美日韩综合一区二区三区| 亚洲伊人久久大香线蕉综合图片 | 欧美精品成人影院| 亚洲精品不卡无码福利在线观看| 黑人巨大精品欧美| 久热国产精品视频一区二区三区| 婷婷开心深爱五月天播播| 四虎永久在线精品免费观看网站| 亚洲国产三级在线观看| 亚洲成人精品久久久| 怡红院av一区二区三区| 免费av在线| 一进一出抽搐gif| 男女性爽大片视频| 熟妇的味道hd中文字幕| 国产无遮挡又黄又爽无vip|