国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > CSS > 正文

網頁制作中的水平居中和垂直居中解決方法集合

2024-07-11 08:46:24
字體:
來源:轉載
供稿:網友
在VeVb.com中,大量的文章介紹了這些知識。在和別人合作的時候,你的代碼的自適應性就需要做到最大程度的好。你自己在做自己的網頁的時候或許可以保證在視覺上是居中的,但是如果讓這個元素或者他的父元素變大了,你還能保證居中嗎?

  vertical-align是個不錯的屬性,但是這個屬性起初是針對表格的cell的。當然這個屬性雖然對塊級元素不起作用,但是對行內元素比如span還是有作用的(這時候,這個屬性設置為負值元素內容就下移,正值則上移)。

  下面是比較專業的垂直居中的集中解決方案。記錄于此,以便查閱。

1、單行垂直居中

  文字在層中垂直居中vertical-align 屬性是做不到的.我們這里有個比較巧妙的方法就是:設置height的高度與line-height的高度相同! 

<div style="line-height:500px;height:500;">

2、層水平居中

  設置div的寬度小于父div的寬度,設置 margin:0 auto;,即可讓div居中。

#parentdiv
{
width: 500px;
}
#childdiv {
width: 200px;
margin:0 auto;
}

3、層中的文字水平居中

  在childdiv的css加上text-align:center;

#parentdiv
{
width: 500px;
}
#childdiv {
width: 200px;
margin:0 auto;
text-align:center;
}

4、div層垂直居中

<div style="width:275px;height:375px;border: solid red;">
<div style=" background:green;height: 375px; width: 275px; position: relative; display: table-cell; vertical-align: middle;">
     <div
           style=" background:red;position:static;position:absolute/9; top: 50%;">
        <div
            style=" background:blue;position: relative; top: -50%;">
                     www.jb51.com
         </div>
      </div>
   </div>
</div>

5、div層垂直水平居中,英文超長換行

   <div style="float:left;width:275px;height:375px;border: solid red;">
<div
          style=" height: 375px; width: 275px; position: relative; display: table-cell; vertical-align: middle;">
          <div
           style="position:static;position:absolute/9; top: 50%;">
           <div style="position: relative; top: -50%; text-align: center;">
              <div style="width: 85px;WORD-WRAP: break-word;TABLE-LAYOUT: fixed;word-break:break-all;margin:0 auto;">
            www.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.com 
              </div>
                     
              </div>
          </div>
         </div>
</div>

6、div垂直滾動

<div
              style="width: 160px; height: 260px; overflow-y: scroll; border: 1px solid;">


              www.jb51.com
             </div>

7、垂直居中和使用text-align水平居中

<div style="float:left;width:275px;height:375px;border: solid red;">
<div
          style=" height: 375px; width: 275px; position: relative; display: table-cell; vertical-align: middle;">
          <div
           style="position:static;position:absolute/9;top: 50%;">
           <div
            style="position: relative; top: -50%; text-align:center;">
            <div style="width: 275px;">
                      <div style="width: 160px;WORD-WRAP: break-word;TABLE-LAYOUT: fixed;word-break:break-all;text-align:left;">
            www.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.com
              </div>
              </div>
                     
              </div>
          </div>
         </div>
</div>

8、垂直居中和使用margin水平居中

    <div style="float:left;width:275px;height:375px;border: solid red;">
<div
          style=" height: 375px; width: 275px; position: relative; display: table-cell; vertical-align: middle;">
          <div
           style="position:static;position:absolute/9; top: 50%;">
           <div
            style="position: relative; top: -50%; ">
            
                      <div style="margin:0 auto;width: 160px;WORD-WRAP: break-word;TABLE-LAYOUT: fixed;word-break:break-all;">
            www.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.com
              </div>
             
                     
              </div>
          </div>
         </div>
</div>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 德清县| 邵武市| 东宁县| 东兴市| 成武县| 永和县| 碌曲县| 富源县| 山阴县| 富裕县| 东乡族自治县| 金门县| 方正县| 密山市| 新建县| 弋阳县| 新乡市| 黔南| 绥芬河市| 南靖县| 新营市| 上思县| 延安市| 星子县| 彝良县| 得荣县| 车致| 射阳县| 盘锦市| 增城市| 沐川县| 忻城县| 襄城县| 丹阳市| 泗洪县| 武胜县| 松江区| 荥经县| 钦州市| 鹤壁市| 金秀|