zoukankan      html  css  js  c++  java
  • 关于width的继承和获取

    absolute元素(如果没有设置width值),其宽度自适应于内部元素,

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <style>
            body,
            html {
                margin: 0;
                padding: 0
            }
            
            .div1 {
                width: 100%;
                height: 300px;
                background: red
            }
            
            .div2 {
                background: blue;
                height: 200px;
                position: absolute;
            }
            
            .div3 {
                width: 100px;
                background: yellow;
                height: 50px;
            }
        </style>
    </head>
    
    <body>
        <div class="div1">
            <div class="div2">
                <div class="div3"></div>
            </div>
        </div>
    </body>
    
    </html>

    
    
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <style>
            body,
            html {
                margin: 0;
                padding: 0
            }
            
            .div1 {
                /*  100%; */
                height: 300px;
                background: red
            }
            
            .div2 {
                background: blue;
                height: 200px
            }
            
            .div3 {
                width: 100px;
                background: yellow;
                height: 50px;
            }
        </style>
    </head>
    
    <body>
        <div class="div1">
            <div class="div2">
                <div class="div3"></div>
            </div>
        </div>
    </body>
    
    </html>
    
    

    如果最外层div 不给宽度,内层div不设置宽度,则宽度均为100%;



  • 相关阅读:
    设计模式复习-单例模式
    设计模式复习-组合模式
    设计模式复习-迭代器模式
    设计模式复习-备忘录模式
    PAT 1085 PAT单位排行 (Microsoft_zzt)
    PAT L1-034 点赞
    PAT L1-032 Left-pad
    PAT 甲级 1046 Shortest Distance
    PAT 甲级 1077 Kuchiguse
    PAT 甲级 1027 Colors in Mars
  • 原文地址:https://www.cnblogs.com/moxiaowohuwei/p/7506259.html
Copyright © 2011-2022 走看看