zoukankan      html  css  js  c++  java
  • CSS----布局注意事项

    1.当div标签中含有子标签,如果div标签的大小是被div中的子标签撑起来的,那么可能布局(之后)可能就会出现问题(if 父级div中没有border,padding,inlinecontent,子级div的margin会一直向上找,直到找到某个标签包括border,padding,inline content中的其中一个,然后按此div 进行margin;)

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            body{
                margin: 0;
            }
            .outer{
                background-color: gold;
                 300px;
                height: 300px;
                overflow: hidden;
            }
            .box1{
                 100px;
                height: 100px;
                background-color: blue;
                margin-top:10px;        /*margin-top 是以id =div1 的这个标签*/
            }
            .box2{
                 100px;
                height: 100px;
                background-color: darksalmon;
                /*如果这样的话就合适呢,对着就下去了*/
                margin-top: 10px;
            }
        </style>
    </head>
    <body>
    <div id="div1" style="background-color: burlywood; 300px; height
    :300px"></div>
    <div style="background-color: chartreuse">
        <div class="box1"></div> 
        <div class="box2"></div>
    </div>
    </body>
    </html>
    示例1
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            body{
                margin: 0;
            }
            .outer{
                background-color: gold;
                 300px;
                height: 300px;
                overflow: hidden;
            }
            .box1{
                 100px;
                height: 100px;
                background-color: blue;
                margin-top:10px;        /*margin-top 是以class=outer 的这个标签*/
            }
            .box2{
                 100px;
                height: 100px;
                background-color: darksalmon;
                /*如果这样的话就合适呢,对着就下去了*/
                margin-top: 10px;
            }
        </style>
    </head>
    <body>
    <div id="div1" style="background-color: burlywood; 300px; height
    :300px"></div>
    <div class="outer">
        <div class="box1"></div>
        <div class="box2"></div>
    </div>
    </body>
    </html>
    示例2

      解决方法:设置padding bording,让div便签称为子标签的真正的父标签

            这两种会改变结构
                1.加上padding
                2.加上border
            不改变结构
                3.overflow:hidden   (理解:相当给div标签设置了隐藏的边界,否则不会出现超出部分隐藏功能了),还有一点,overflow:hidden 清除浮动


     
  • 相关阅读:
    [HDOJ1261]最少拦截系统
    Gym 100637F F. The Pool for Lucky Ones
    Codeforces Gym 100637A A. Nano alarm-clocks 前缀和处理
    HDU 1166 敌兵布阵 线段树
    【Tyvj1038】忠诚 线段树
    Codeforces Gym 100513G G. FacePalm Accounting
    Codeforces Round #313 (Div. 2)B.B. Gerald is into Art
    Codeforces Round #313 (Div. 2) D. Equivalent Strings
    Codeforces Round #313 (Div. 2) C. Gerald's Hexagon 数学
    Codeforces Round #313 (Div. 2) A. Currency System in Geraldion
  • 原文地址:https://www.cnblogs.com/yanxiaoge/p/10530060.html
Copyright © 2011-2022 走看看