zoukankan      html  css  js  c++  java
  • (前端)html与css css 14、父子盒模型

    父子盒模型

    子盒子的整体占位不能超过父盒子的内容区域

    父盒子的内容区域宽度≥子盒子width+padding*2+border*2

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
        <title>Document</title>
        <style type="text/css">
            *{
                margin: 0;
                padding: 0;
            }
            .outer{
                width: 400px;
                height: 400px;
                border: 1px solid red;
                margin: 20px auto;
            }
            .inner{
                width: 360px;
                height: 200px;
                padding: 0 20px;
                background-color: skyblue;
                margin: 0 auto;
            }
        </style>
    </head>
    <body>
        <div class="outer">
            <div class="inner"></div>
        </div>
    </body>
    </html>
    View Code

    如果子盒子不设置宽度,会自动撑满父亲,宽度是父亲的100%,如果你再设置边框,边距,他会自动内减,不需要再手动减少width。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
        <title>Document</title>
        <style type="text/css">
            *{
                margin: 0;
                padding: 0;
            }
            .outer{
                width: 500px;
                border: 1px solid red;
                margin: 20px auto;
            }
            .inner{
                padding: 10 20px;
                background-color: skyblue;
                line-height: 28px;
                border: 6px solid blue;
            }
        </style>
    </head>
    <body>
        <div class="outer">
            <div class="inner">文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文</div>
        </div>
    </body>
    </html>
    View Code

  • 相关阅读:
    YOLO V5 is Here! Custom Object Detection Tutorial with YOLO V5
    pjsip application notes
    Tilt Angle Visualization With Edison, Accelerometer and Python
    WebRTC 镜像源
    Get Started with WebRTC
    sqlserver关于发布订阅replication_subscription的总结
    在Flask中,g是什么?它的生命周期是?能做什么?
    46.全排列问题
    【LeetCode】代码模板,刷题必会
    QEMU+KVM学习笔记
  • 原文地址:https://www.cnblogs.com/StevenSunYiwen/p/11205414.html
Copyright © 2011-2022 走看看