濮阳杆衣贸易有限公司

主頁 > 知識庫 > 詳解左右寬度固定中間自適應(yīng)html布局解決方案

詳解左右寬度固定中間自適應(yīng)html布局解決方案

熱門標簽:朝陽自動外呼系統(tǒng) 400電話辦理尚景 商丘電話自動外呼系統(tǒng)怎么收費 默納克系統(tǒng)外呼顯示inns 東莞人工外呼系統(tǒng)多少錢 周口導(dǎo)航地圖標注 地圖標注地點下載 400電話是在哪里申請 昌邑外呼系統(tǒng)

本文介紹了詳解左右寬度固定中間自適應(yīng)html布局解決方案,分享給大家,具體如下:

a.使用浮動布局

html結(jié)構(gòu)如下

<div class="box">
    <div class="left">left</div>
    <div class="right">right</div>
    <div class="center">center</div>
</div>   
//此處注意要先渲染左、右浮動的元素才到中間的元素。元素浮動后剩余兄弟塊級元素會占滿父元素的寬度
<style>
   .box{
        height:200px;
    }    
    .left{
        float:left;
        width:300px;
    }
    .right{
        float:right;
        width:300px;
    }
</style>

b.使用固定定位

html結(jié)構(gòu)如下

<div class="box">
    <div class="left">left</div>
    <div class="right">right</div>
     <div class="center">center</div>
</div> 
//和浮動布局同理,先渲染左右元素,使其定位在父元素的左右兩端,剩余的中間元素占滿父元素剩余寬度。
<style>
    .box{
        position: relative;
      }
      .left{
        position: absolute;
        width: 100px;
        left: 0;
      }
      .right{
        width:100px;
        position: absolute;
        right: 0;
      }
      .center{
        margin: 0 100px;
        background: red;
      }
</style>

c.表格布局

將父元素display:table,子元素display:table-cell,會將它變?yōu)樾袃?nèi)塊。

這種布局方式的優(yōu)點是兼容性好。

<div class="box">
  <div class="left">
    left
  </div>
  <div class="center">
    center
  </div>
  <div class="right">
    right
  </div>
</div>
<style>
    .box{
        display: table;
        width: 100%;
      }
      .left{
        display: table-cell;
        width: 100px;
        left: 0;
      }
      .right{
        width:100px;
        display: table-cell;
      }
      .center{
        width: 100%;
        background: red;
      }
</style>

d.彈性布局

父元素display:flex子元素會全部并列在一排。

子元素中flex:n的寬度會將父元素的寬度/n

如flex:1,寬度就等于父元素高度。

彈性布局的缺點是兼容性不高,目前IE瀏覽器無法使用彈性布局

<div class="box">
  <div class="left">
    left
  </div>
  <div class="center">
    center
  </div>
  <div class="right">
    right
  </div>
</div>
<style>
    .box{
        display: flex;
        width: 100%;
      }
      .left{
      
        width: 100px;
        left: 0;
      }
      .right{
        width:100px;
      }
      .center{
        flex:1;
      }
</style>

e.網(wǎng)格布局

父元素display:grid;

grid-templatecolumns:100px auto 100px;

依次為第一個子元素寬100px 第二個自適應(yīng) 第三個100px;

網(wǎng)格布局的優(yōu)點是極為簡便,直接通過父元素樣式?jīng)Q定,缺點是兼容性不高。

<div class="box">
  <div class="left">
    left
  </div>
  <div class="center">
    center
  </div>
  <div class="right">
    right
  </div>
</div>
<style>
  .box{
        display: grid;
        grid-template-columns: 100px auto 100px;
        width: 100%;
      }
</style>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

標簽:揭陽 沈陽 健身房 湖南 銅陵 那曲 福建 阿拉善盟

巨人網(wǎng)絡(luò)通訊聲明:本文標題《詳解左右寬度固定中間自適應(yīng)html布局解決方案》,本文關(guān)鍵詞  詳解,左右,寬度,固定,中間,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《詳解左右寬度固定中間自適應(yīng)html布局解決方案》相關(guān)的同類信息!
  • 本頁收集關(guān)于詳解左右寬度固定中間自適應(yīng)html布局解決方案的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    荔浦县| 太谷县| 阜平县| 雷波县| 天气| 怀安县| 乌拉特前旗| 罗田县| 鹤壁市| 班玛县| 临清市| 阿城市| 金堂县| 新巴尔虎右旗| 溧水县| 麦盖提县| 淮安市| 巴南区| 佛教| 长子县| 开封市| 桂林市| 清水县| 永定县| 庆元县| 大田县| 霍山县| 当阳市| 紫金县| 上虞市| 和静县| 陇西县| 秭归县| 额尔古纳市| 古交市| 德钦县| 普安县| 香港| 英超| 明溪县| 修文县|