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

  • 相关阅读:
    微信端H5页面问题总结
    css英文长文字会自动换行的解决办法
    前端面试题二(来自前端网http://www.qdfuns.com/notes/23515/fa8b1e788ac39b04108fc33e5b543c4a.html)
    前端面试题(来自前端网http://www.qdfuns.com/notes/23515/c9163ddd620baac5dd23141d41982bb8.html)
    js中的闭包
    js中this的运用
    关于echart x轴溢出的解决办法
    关于jsonp的学习
    关于获取浏览器参数的见解
    关于echar彩色柱状图颜色配置问题
  • 原文地址:https://www.cnblogs.com/StevenSunYiwen/p/11205414.html
Copyright © 2011-2022 走看看