成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

【芝士整理】CSS經(jīng)典布局

chavesgu / 3438人閱讀

摘要:水平居中行內(nèi)元素定寬塊元素常規(guī)流中浮動(dòng)塊元素負(fù)邊距絕對(duì)定位元素負(fù)邊距居中絕對(duì)居中不定寬塊元素完整垂直居中單行和一致定高塊元素負(fù)邊距居中絕對(duì)居中不定高塊元素完整水平垂直居中行內(nèi)元素

水平居中 行內(nèi)元素

text-align

.parent {
    text-align: center;
}
定寬塊元素 常規(guī)流中

margin: 0 auto;

.child {
    width: 200px;
    margin: 0 auto;
}
浮動(dòng)塊元素

relative + 負(fù)邊距

.child {
    width: 200px;
    float: left;
    position: relative;
    left: 50%;
    margin-left: -100px;
}
絕對(duì)定位元素

負(fù)邊距居中

.parent {
    position: relative;
}
.child {
    width: 200px;
    position: absolute;
    left: 50%;
    margin-left: -100px;
}

絕對(duì)居中

.parent {
    position: relative;
}
.child {
    width: 200px;
    position: absolute;
    left: 0;
    right: 0;
    margin: 0 auto;
}
不定寬塊元素

inline-block + text-align

.parent{
    text-align: center;
}
.child{
    display: inline-block;
}

transform

.parent {
    position: relative;
    height: 300px;
}
.child {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

flexbox

.parent {
    display: flex;
    flex-direction: row;
    justify-content: center;
}

table + margin:auto

.parent {
    display: table;
      margin: 0 auto;
}

table-cell + text-align

.table {
  display: table;
  width: 100%;
}
.table-cell {
  display: table-cell;
  text-align: center;
}

PS: 完整Demo - https://codepen.io/curlywater...

垂直居中 單行

line-height和height一致

.child {
    height: 100px;
    line-height: 100px;
}
定高塊元素

負(fù)邊距居中

.parent {
    position: relative;
}
.child {
    width: 200px;
    position: absolute;
    top: 50%;
    margin-top: -100px;
}

絕對(duì)居中

.parent {
    position: relative;
}
.child {
    width: 200px;
    position: absolute;
    top: 0;
    bottom: 0;
    margin: auto;
}
不定高塊元素

transform

.parent {
    position: relative;
    height: 300px;
}
.child {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}

flex

.parent {
    display: flex;
    align-items: center;
    height: 300px;
}

table-cell + vertical-align

.parent {
    display: table-cell;
      vertical-align: middle;
      height: 300px;
}

PS: 完整Demo - https://codepen.io/curlywater...

水平垂直居中 行內(nèi)元素

text-align: center + line-height一致 + vertical-align: middle (近似居中)

.parent {
    text-align: center;
    line-height: 300px;
    height: 300px;
    text-align: center;
}
.child {
    vertical-align: middle;
}
定高定寬塊元素

負(fù)邊距居中

.parent {
    position: relative;
}
.child {
    width: 200px;
    height: 200px;
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -100px;
    margin-top: -100px;
}

絕對(duì)居中定位

.parent {
    position: relative;
}
.child {
    width: 200px;
    height: 200px;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
}
不定塊元素

transform

.parent {
    position: relative;
}
.child {
    position: absolute;
    top: 50%;
    bottom: 50%;
    transform: translate(-50%, -50%);
}

flex

.parent {
    display: flex;
    justify-content: center;
    align-items: center;
}

table-cell + text-align + vertical-align

.parent {
    display: table-cell;
    text-align: center;
    vertical-align: middle;
}
.child {
    display: inline-block;
}

PS: 完整Demo - https://codepen.io/curlywater...

上下布局

calc()

.header {
    height: 200px;
}
.content {
    height: calc(100% - 200px);
}

content absolute

.header {
    height: 200px;
}
.content {
    position: absolute;
    width: 100%;
    top: 200px;
    bottom: 0;
}

header absolute

.content {
    height: 100%;
    padding-top: 100px;
    box-sizing: border-box;
}
.header {
    position: absolute;
    height: 100px;
    width: 100%;
}

flex

.container {
    display: flex;
    flex-direction: column;
}
.content {
    flex: 1;
}

table(table-row里需要有內(nèi)容)

.container {
    display: table;
}
.header, .content {
    display: table-row;
}

PS: 完整Demo - https://codepen.io/curlywater...

左右布局

float + margin

.left {
    width: 200px;
    float: left;
}
.right {
    margin-left: -200px;
}

float + BFC(左右兩邊都可自適應(yīng))

.left {
    float: left;
}
.right {
    overflow: auto;
}

PS: 完整Demo - https://codepen.io/curlywater...

左中右布局

left + right + margin(注意DOM節(jié)點(diǎn)順序)

.left {
    float: left;
    width: 100px;
}
.right {
    float: right;
    width: 200px;
}c
.main {
    margin-left: 100px;
    margin-right: 200px;
    height: 100%;
}

float + BFC

.left {
    float: left;
     width: 100px;
}
.right {
    float: right;
    width: 200px;
}
.main {
    overflow: auto;
    height: 100%;
}

圣杯

https://codepen.io/curlywater...

雙飛翼

https://codepen.io/curlywater...

flex

.container {
    display: flex;
}
.main {
    flex: 1;
}

table

.container{
    display: table; 
    width: 100%;
    table-layout: fixed;
}
.left,.main,.right{
    display: table-cell;
}
.main {
    width: 100%;
}

https://codepen.io/curlywater...

等高

padding + margin

.container {
  overflow: hidden;
  .left,
  .right {
    padding-bottom: 9999px;
    margin-bottom: -9999px;
  }
  .left {
    float: left;
    width: 300px;
    background: #333;
    color: #fff;
  }
  .right {
    overflow: hidden;
  }
}

border

.container {
  border-left: 300px solid #333;
  .left {
    float: left;
    margin-left: -300px;
    color: #fff;
  }
  .right {
    height: 100%;
  }
}

table

.container {
  display: table;
  width: 100%;
  .left, .right {
    display: table-cell;
  }
  .left {
    width: 300px;
    background: #333;
    color: #fff;
  }
}

flex

.container {
  display: flex;
  .left {
    width: 300px;
    background: #333;
    color: #fff;
  }
}

https://codepen.io/curlywater...

等分

百分比

.container {
    margin-left: -20px;
    font-size: 0;
}
.item {
    width: 25%;
    padding-left: 20px;
    display: inline-block;
    box-sizing: border-box;
}

flex

.container {
    display: flex;
}
.item {
    flex: 1;
}
.item + .item {
    margin-left: 20px;
}

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/117049.html

相關(guān)文章

  • 芝士整理CSS基礎(chǔ)圖譜

    摘要:為了實(shí)現(xiàn)文字環(huán)繞效果,規(guī)范規(guī)定的措施是使父容器塌陷,元素脫離文檔流浮動(dòng)產(chǎn)生,元素周圍的內(nèi)容轉(zhuǎn)換為圍繞元素排列。 選擇器注意點(diǎn) 屬性選擇器 [attr^=value] - 開頭或全等 [attr$=value] - 結(jié)尾或全等 [attr*=value] - 包含值 [attr~=value] - 字符串包含 選擇器組 A > B - 直接子節(jié)點(diǎn) A + B - 下一個(gè)兄弟節(jié)點(diǎn) A...

    iOS122 評(píng)論0 收藏0
  • 【前端芝士樹】如何對(duì)元素塊實(shí)現(xiàn)居中(垂直和水平方向都居中)?

    摘要:前端芝士樹如何對(duì)元素塊實(shí)現(xiàn)垂直居中水平居中和垂直居中是前端開發(fā)過程中肯定會(huì)遇到的問題,下面我講解幾種常見的方式。 【前端芝士樹】如何對(duì)元素塊實(shí)現(xiàn)垂直居中? showImg(https://segmentfault.com/img/bVbisNT?w=430&h=183); 水平居中和垂直居中是前端開發(fā)過程中肯定會(huì)遇到的問題,下面我講解幾種常見的方式。 1/ 利用Flex布局來實(shí)現(xiàn)極速居...

    _Dreams 評(píng)論0 收藏0
  • 【前端芝士樹】如何對(duì)元素塊實(shí)現(xiàn)居中(垂直和水平方向都居中)?

    摘要:前端芝士樹如何對(duì)元素塊實(shí)現(xiàn)垂直居中水平居中和垂直居中是前端開發(fā)過程中肯定會(huì)遇到的問題,下面我講解幾種常見的方式。 【前端芝士樹】如何對(duì)元素塊實(shí)現(xiàn)垂直居中? showImg(https://segmentfault.com/img/bVbisNT?w=430&h=183); 水平居中和垂直居中是前端開發(fā)過程中肯定會(huì)遇到的問題,下面我講解幾種常見的方式。 1/ 利用Flex布局來實(shí)現(xiàn)極速居...

    baoxl 評(píng)論0 收藏0
  • 芝士整理】JS基礎(chǔ)圖譜

    摘要:沒有找到的話,看上級(jí)函數(shù)作用域,向上查找到,找到為止。將會(huì)在執(zhí)行上下文棧中保留上級(jí)作用域的執(zhí)行上下文。若在閉包使用完畢之后不手動(dòng)解除引用,相關(guān)執(zhí)行上下文將會(huì)一直保留于執(zhí)行上下文棧中,占據(jù)內(nèi)存空間,若持續(xù)積累,容易造成內(nèi)存泄漏。 JS有哪些基本數(shù)據(jù)類型呢? 值類型:undefined, Number, Boolean, String,null 引用類型:Object 值類型存放在棧中 引...

    netScorpion 評(píng)論0 收藏0
  • CSS 布局經(jīng)典問題初步整理

    摘要:布局經(jīng)典問題初步整理標(biāo)簽前端本文主要對(duì)布局中常見的經(jīng)典問題進(jìn)行簡(jiǎn)單說明,并提供相關(guān)解決方案的參考鏈接,涉及到三欄式布局,負(fù),清除浮動(dòng),居中布局,響應(yīng)式設(shè)計(jì),布局,等等。 CSS 布局經(jīng)典問題初步整理 標(biāo)簽 : 前端 [TOC] 本文主要對(duì) CSS 布局中常見的經(jīng)典問題進(jìn)行簡(jiǎn)單說明,并提供相關(guān)解決方案的參考鏈接,涉及到三欄式布局,負(fù) margin,清除浮動(dòng),居中布局,響應(yīng)式設(shè)計(jì),F(xiàn)l...

    Amos 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<