婷婷久久综合九色综合,欧美成色婷婷在线观看视频,偷窥视频一区,欧美日本一道道一区二区

<tt id="bu9ss"></tt>
  • <span id="bu9ss"></span>
  • <pre id="bu9ss"><tt id="bu9ss"></tt></pre>
    <label id="bu9ss"></label>

    當(dāng)前位置:首頁(yè) >  IDC >  服務(wù)器 >  正文

    CSS子元素跟父元素的高度一致的實(shí)現(xiàn)方法

     2020-10-19 16:34  來(lái)源: 腳本之家   我來(lái)投稿 撤稿糾錯(cuò)

      阿里云優(yōu)惠券 先領(lǐng)券再下單

    這篇文章主要介紹了CSS子元素跟父元素的高度一致的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

    絕對(duì)定位方法:

    (1)將父元素設(shè)置為相對(duì)定位,不寫(xiě)父元素的高度時(shí),會(huì)隨著左邊的子元素高度變化而變化

    .parent {
    /*關(guān)鍵代碼*/
    position: relative;

    /*其他樣式*/
    width: 800px;
    color: #fff;
    font-family: "Microsoft Yahei";
    text-align: center;
    }

    (2)左邊一個(gè)元素有個(gè)最小高度的情況

    .left {
    min-height: 700px;
    width: 600px;
    }

    (3)右邊元素要想跟父元素的高度是一致,那么可以用絕對(duì)定位這樣設(shè)置,如果不想同時(shí)寫(xiě)top和bottom,寫(xiě)一個(gè)時(shí),再寫(xiě)上height:100%,也可以達(dá)到一樣的效果

    .right {
    /*關(guān)鍵代碼*/
    width: 200px;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;

    /*其他樣式*/
    background: #ccc;

    }

    (4)完整例子代碼:

    <!DOCTYPE html>
    <html >
    <head>
    <meta charset="UTF-8">
    <title>子元素高度與父元素一致</title>
    <style>

    .parent{
    position: relative;
    background: #f89;

    width: 800px;
    color: #fff;
    font-family: "Microsoft Yahei";
    text-align: center;
    }
    .left {
    min-height: 700px;
    width: 600px;

    }
    .right {
    width: 200px;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;

    background: #ccc;

    }
    </style>
    </head>
    <body>
    <div class="parent">
    <div class="left">
    左側(cè) left 不定高,parent的高度隨著左側(cè)left 的高度變化而變化,右側(cè)也跟著變
    </div>
    <div class="right">
    這邊的高度跟父元素高度一致
    </div>
    </div>
    </body>
    </html>

     

    左側(cè) left 不定高,parent的高度隨著左側(cè)left 的高度變化而變化,右側(cè)也跟著變

    這邊的高度跟父元素高度一致

    (5)效果

    (6)問(wèn)題來(lái)了:

    如果右側(cè)的子元素高度超出了.parent,怎么辦?

    right的子元素,高度為1024px,會(huì)撐破容器,給.right加上 overflow:auto 就防止溢出了

    .right-inner {
    background: limegreen;
    height: 1024px;
    }

    效果圖如下:

    完整代碼:

    <!DOCTYPE html>
    <html >
    <head>
    <meta charset="UTF-8">
    <title>子元素高度與父元素一致</title>
    <style>

    .parent{
    position: relative;
    background: #f89;

    width: 800px;
    color: #fff;
    font-family: "Microsoft Yahei";
    text-align: center;
    }
    .left {
    min-height: 700px;
    width: 600px;

    }
    .right {
    width: 200px;
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;

    overflow: auto;

    background: #ccc;

    }
    .right-inner {
    background: limegreen;
    height: 1024px;
    }
    </style>
    </head>
    <body>
    <div class="parent">
    <div class="left">
    左側(cè) left 不定高,parent的高度隨著左側(cè)left 的高度變化而變化,右側(cè)也跟著變
    </div>
    <div class="right">
    <div class="right-inner">right的子元素,高度為1024px,會(huì)撐破容器,給.right加上 overflow:auto 就防止溢出了</div>
    </div>
    </div>
    </body>
    </html>

    左側(cè) left 不定高,parent的高度隨著左側(cè)left 的高度變化而變化,右側(cè)也跟著變

    right的子元素,高度為1024px,會(huì)撐破容器,給.right加上 overflow:auto 就防止溢出了

    (7)其他資源

    http://stackoverflow.com/questions/3049783/how-to-make-a-floated-div-100-height-of-its-parent

    文章來(lái)源:腳本之家,原文鏈接:https://www.jb51.net/css/743410.html

    申請(qǐng)創(chuàng)業(yè)報(bào)道,分享創(chuàng)業(yè)好點(diǎn)子。點(diǎn)擊此處,共同探討創(chuàng)業(yè)新機(jī)遇!

    相關(guān)文章

    熱門(mén)排行

    信息推薦