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

資訊專欄INFORMATION COLUMN

[note]布局:列等高,水平垂直居中,固定頁腳

Chao / 2409人閱讀

摘要:等高列布局兩列結(jié)構(gòu)兩邊都加上跟相等的負(fù)值,可以實現(xiàn)邊框效果等同兩列流體布局多列值要夠大結(jié)構(gòu)三列固定寬度結(jié)構(gòu)三列自適應(yīng)布局實用結(jié)構(gòu)多列布局現(xiàn)代瀏覽器結(jié)構(gòu)水平垂直

等高列布局 兩列/marginLeft

html結(jié)構(gòu):.wrap>.container>.sidebar+.main
marginLeft,marginRight兩邊都加上跟borderWidth相等的負(fù)值,可以實現(xiàn)邊框效果

/*1: 等同*/
.container {
  border-left-width: 200px;/*1*/
}
.sidebar {
  float: left;
  width: 200px;/*1*/
  margin-left: -200px;/*1*/
  margin-right: -1px;
  border-right: 1px solid #888;
}
.main {
  float: left;
  margin-left: -1px;
  border-left: 1px solid #888;
}

http://codepen.io/zplus/pen/N...

兩列/流體布局-border
.main {
  width: 100%;
  border-right: 220px solid #f00;
  margin-right: -220px;
}
.sidebar {
  width: 220px;
  background: #f00;
}

http://codepen.io/zplus/pen/X...

多列/(+padding)+(-margin)=0

padding,margin值要夠大
html結(jié)構(gòu):.container>.left+.main+.right

.container {
  overflow: hidden;
}
.column {
  margin-bottom: -99999px;
  padding-bottom: 99999px;
}

http://codepen.io/zplus/pen/w...

三列固定寬度/border

html結(jié)構(gòu):.wrap>.container>.main+.left+.right

.container {
  width: 520px;
  border-left: 220px solid #0f0; /*==leftWidth*/
  border-right: 220px solid #f00;/*==rightWidth*/
}
.left {
  float: left;
  width: 220px;
  margin-left: -220px;
}
.main {
  float: left;
  width: 520px;
  margin-right: -520px;
}
.right {
  float: right;
  width: 220px;
  margin-right: -220px;
}

http://codepen.io/zplus/pen/J...

三列自適應(yīng)布局(實用)

html結(jié)構(gòu):.container>.main+.left+.right

.container {
  width: 100%;
  float: left;
  border-left: 220px solid #0f0;
  border-right: 220px solid #f00;
  display: inline; /*IE*/
}
.main {
  float: left;
  width: 100%;
  margin-right: -100%;
}
.left {
  float: left;
  width: 220px;
  margin-left: -220px;
}
.right {
  float: right;
  width: 220px;
  margin-right: -220px;
}

http://codepen.io/zplus/pen/b...

多列布局/table(現(xiàn)代瀏覽器)

html結(jié)構(gòu):.table>.table-row>.table-cell+.table-cell+.table-cell

.table {
  display: table;
  &-row {
    display: table-row;
  }
  &-cell {
    display: table-cell;
    width: 33%;
  }
}

http://codepen.io/zplus/pen/b...

水平垂直居中 flexbox方式
body {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;/*firefox下需要*/
}

http://codepen.io/zplus/pen/m...

transform與絕對定位方式
img {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

https://codepen.io/zplus/pen/...

偽元素方式

運用inline-block配合空標(biāo)簽,這里使用偽元素替代

body {
  text-align: center;
  &:after {
    content: "";
    display: inline-block;
    vertical-align: middle;
    height: 100%;
    width: 0;
  }
}

https://codepen.io/zplus/pen/...

固定頁腳 模擬表格方式

html結(jié)構(gòu):.wrap>.container+.footer

.wrap {
  display: table;
  table-layout: fixed;
  > div {
      display: table-row;
      height: 1px;
  }
  .container {
    height: auto;
  }
}

http://codepen.io/zplus/pen/o...

負(fù)marginBottom方式

html結(jié)構(gòu):.wrap>.container+.footer

  html, body {
    height: 100%;
  }
  #{$root-selector} {
    min-height: 100%;
    height: auto !important;
    height: 100%;
    margin-bottom: -$footer-height;
    &:after {/*可用空標(biāo)簽替代*/
      content: "";
      display: block;
      height: $footer-height;
    }
  }
  #{$footer-selector} {
    height: $footer-height;
  }

http://codepen.io/zplus/pen/q...

padding+position方式

html結(jié)構(gòu):.wrap>.container+.footer

.wrap {
  position: relative;
}
.container {
  padding-bottom: 60px; /*==footerHeight*/
}
.footer {
  position: absolute; /*基于wrap的定位*/
  bottom: 0;
  height: 60px; /*footerHeight*/
}

http://codepen.io/zplus/pen/X...

負(fù)marginTop方式

html結(jié)構(gòu):.wrap>.container^+.footer

html, body {
  height: 100%;
}
.wrap {
  min-height: 100%;
  height: auto !important;
  height: 100%;
}
.container {
  padding-bottom: 60px; /*==footerHeight*/
}
.footer {
  margin-top: -60px; /*==footerHeight*/
  height: 60px;
}

http://codepen.io/zplus/pen/x...

借助javascript

http://codepen.io/zplus/pen/O...

垂直居中 inline-block+偽元素

在垂直居中的元素上添加偽元素,設(shè)置偽元素的高==父級容器的高,然后為文本添加vertical-align:middle

.ghost-center {
  position: relative;
  &::before {
    content: "";
    display: inline-block;
    height: 100%;
    width: 1%;
    vertical-align: middle;
  }
  p {
    display: inline-block;
    vertical-align: middle;
  }
}

http://codepen.io/zplus/pen/M...

Sass mixin方法
@mixin center($width: null, $height: null) {
  position: absolute;
  top: 50%;
  left: 50%;
  
  @if not $width and not $height {
    transform: translate(-50%, -50%);
  } @else if $width and $height {
    width: $width;
    height: $height;
    margin: -($width/2) #{0 0} -($height/2);
  } @else if not $height {
    width: $width;
    margin-left: -($width/2);
    transform: translateY(-50%);
  } @else {
    height: $height;
    margin-top: -($height/2);
    transform: translateX(-50%);
  }
}

/*flexbox方法*/
@mixin center-children {
  display: flex;
  justify-content: center;
  align-items: center;
}

http://codepen.io/zplus/pen/p...

參考網(wǎng)址:

再談等高列布局、水平垂直居中與置頂頁腳
八種創(chuàng)建等高列布局
CSS居中完整指南
使用Sass制作居中效果

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

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

相關(guān)文章

  • 構(gòu)建靜態(tài)頁面 之 [ 布局 ]

    摘要:布局描述表示對頁面中的顯示效果進(jìn)行一些排列水平方向居中垂直方向居中居中布局水平方向居中第一種方式水平居中行內(nèi)塊級元素水平居中的第一種方法該方法需作用在父子結(jié)構(gòu)中為父級設(shè)置屬性為子級設(shè)置屬性注意的問題屬性是設(shè)置文本內(nèi)容對齊方式的 布局 描述 表示對頁面中的顯示效果進(jìn)行一些排列 水平方向居中 垂直方向居中 居中布局 水平方向居中 第一種方式 水平居中 + 行內(nèi)塊級元素(text-a...

    andot 評論0 收藏0
  • 構(gòu)建靜態(tài)頁面 之 [ 布局 ]

    摘要:布局描述表示對頁面中的顯示效果進(jìn)行一些排列水平方向居中垂直方向居中居中布局水平方向居中第一種方式水平居中行內(nèi)塊級元素水平居中的第一種方法該方法需作用在父子結(jié)構(gòu)中為父級設(shè)置屬性為子級設(shè)置屬性注意的問題屬性是設(shè)置文本內(nèi)容對齊方式的 布局 描述 表示對頁面中的顯示效果進(jìn)行一些排列 水平方向居中 垂直方向居中 居中布局 水平方向居中 第一種方式 水平居中 + 行內(nèi)塊級元素(text-a...

    JessYanCoding 評論0 收藏0
  • CSS 常用的定位和布局方法匯總(已添加源碼地址)

    CSS-Layout 旨在打造詳盡的前端布局代碼學(xué)習(xí)庫(自從用了框架開發(fā),CSS生疏了不少,所以開這個庫練練手)SF不能正確解析含有中文的網(wǎng)址,所以某些預(yù)覽鏈接無法跳轉(zhuǎn),請訪問我的博客閱讀此文 常見定位方法 水平居中 子元素為行內(nèi)元素還是塊狀元素,寬度一定還是寬度未定,采取的布局方案不同。 方案選擇基本思路:子元素為 行內(nèi)元素:對父元素設(shè)置text-align:center; 定寬塊狀元素: 設(shè)...

    loonggg 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<