第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

CSS居中的方法總結(jié)

標(biāo)簽:
Html/CSS

CSS水平和垂直居中在开发中经常用到,在此加以总结。

水平居中方法

1.行内元素水平居中,设置父元素的text-align: center

<div id="box" >
  <span id="content" >center</span></div>
#box {  text-align: center;
}

常用的行内元素有aabbrbbreminputlabelselectspanstrongsubsuptextarea等。

2.宽度固定的块级元素水平居中,设置该元素的margin: 0 auto

<div id="box" >
  <div id="content" >center</div></div>
#box {  width: 64%;  margin: 0 auto;
}

常用的块级元素有addressarticleaudioblockquotecanvasdivfooterformh1headerhroloutputppresectiontableulvideo等。

3.绝对定位元素水平居中,设置父元素position: relative,设置该元素left: 0; right: 0; margin: 0 auto;

<div id="box" >
  <div id="content" >center</div></div>
#box {  position: relative;
 }#content {  position: absolute;  left: 0;  right: 0;  margin: 0 auto;
}

4.flex布局水平居中,设置父元素display: flex; justify-content: center

<div id="box" >
  <div id="content" >center</div></div>
#box {  display: flex;  justify-content: center;
}

垂直居中方法

1.单行文本垂直居中,设置该元素line-height为父元素height高度。

<div id="box" >
  <div id="content" >center</div></div>
#content {  height: 2em;  line-height: 2em;
}

2.将父元素显示为表格display: table-cell,利用vertical-align: middle设置垂直居中。

<div id="box" >
  <div id="content" >center</div></div>
#box {  display: table-cell;  vertical-align: middle;
 }

3.绝对定位该元素并设置父元素positoin: relative,设置该元素top:0; bottom: 0; margin: auto;

<div id="box" >
  <div id="content" >center</div></div>
#box {  position: relative;
 }#content {  position: absolute;  top: 0;  bottom: 0;  marigin: auto;
}

4.绝对定位固定高度是,设置top: 50%margin-top值为高度值的一半。

<div id="box" >
  <div id="content" >center</div></div>
#box {  position: relative;
 }#content {  position: absolute;  height: 12em;  top: 50%;  margin-top: 6em;
}

5.flex布局,设置父元素display: flex; align-items: center

<div id="box" >
  <div id="content" >center</div></div>
#box {  display: flex; 
  align-items: center;
 }



作者:Adambee08
链接:https://www.jianshu.com/p/c38dcdd3d89b


點擊查看更多內(nèi)容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊有機(jī)會得

100積分直接送

付費專欄免費學(xué)

大額優(yōu)惠券免費領(lǐng)

立即參與 放棄機(jī)會
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消