九九热线视频精品99-动漫高h纯肉无码视频在线观看-午夜理论无码片在线观看免费-99精品国产在热久久无码-亚洲国产成人乱码

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

2016/8/26 8:37:10   閱讀:1528    發布者:1528

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

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

主站蜘蛛池模板: 97国语精品自产拍在线观看| 熟女少妇人妻中文字幕| 看免费真人视频网站| 久久亚洲色www成人网址| 亚洲国产成人久久精品大牛影视 | 国产精品视频熟女韵味| 国产欧美日韩亚洲更新| 国内大量偷窥精品视频| 国产 高潮 抽搐 正在播放| 成人片黄网站色大片免费毛片| 天天曰天天躁天天摸孕妇| 帮老师解开蕾丝奶罩吸乳视频| 天天在线看无码av片| 综合久久婷婷综合久久| 国产精品人成视频免费999| 天天狠天天添日日拍捆绑调教| 久久精品熟女人妻一区二区三区| 丰满少妇女裸体bbw| 在线观看麻豆国产传媒61| 娇小萝被两个黑人用半米长| 国产在线一区二区香蕉 在线| 国产专区免费资源网站| 麻麻张开腿让我爽了一夜| 国产真实高潮太爽了| 丰满人妻被黑人连续中出| 国产凹凸在线一区二区| 国产精品国产对白熟妇| 亚洲乱亚洲乱妇小说网| 亚欧欧美人成视频在线| 成视人a免费观看 视频| 天堂中文最新版在线中文| 成人性生交大片免费看r链接| 制服丝袜亚洲中文欧美在线 | 久久久久久国产精品免费免费男同 | 男人的天堂2018无码| 国产v片在线播放免费无码| 亚洲国产成人精品无码区二本| 国产乡下三级全黄三级| 玩弄人妻少妇500系列| 99精品国产综合久久久久五月天| 无线日本视频精品|