CSS水平垂直居中方式

2022-08-13 19:03:18 字數 585 閱讀 8119

1.grid布局實現(一)

.father

2.grid布局實現(二)

.father

3.grid配合margin實現

.father

.son

4.flex布局實現

.father

5.flex配合margin實現

.father

.son

6.使用display:table-cell實現

.father

.son

7.使用絕對定位實現

.father

.son

8.通過內聯元素的特性實現

.father

.father::after

.son

line-height與father元素height一樣

————學習記錄

CSS垂直居中水平居中方法

center 剛在別人的部落格裡看到這種方法時真的覺得很奇葩,以下是大神的解釋 解釋 1 在普通內容流中,margin auto的效果等同於margin top 0 margin bottom 0。2 position absolute使絕對定位塊跳出了內容流,內容流中的其餘部分渲染時絕對定位部分不...

常見居中方式 (水平居中 垂直居中)

1.水平居中 1 子元素 margin 0 auto 2 使用絕對定位 父元素 position relative 子元素 position absolute left 50 transform translatex 50 3 父元素 text align center 子元素 display in...

css垂直水平居中方法

1.塊級元素中的行內元素水平居中 給塊級元素設定 text align center 2.塊級元素1中的塊級元素2水平居中 1 給塊級元素2設定 margin 0 auto 2 給塊級元素2設定 display inline block 給塊級元素1中設定 text align center 1.塊...