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%;



  • 相关阅读:
    排序算法
    顺序表与链表
    二叉树
    查找算法
    15 Django 离线脚本
    poj 1330 Nearest Common Ancestors(LCA 基于二分搜索+st&rmq的LCA)
    hdu 6158 The Designer( 反演圆)
    圆的反演性质
    HDU 6153 A Secret(扩展kmp)
    kmp&扩展kmp
  • 原文地址:https://www.cnblogs.com/moxiaowohuwei/p/7506259.html
Copyright © 2011-2022 走看看