day5

作者: 君_5372 | 来源:发表于2018-07-16 09:22 被阅读0次

1.盒子模型

 <style>
        div{
            width:200px;
            height:200px;
            background:#ff2d51;
            /* 
            box-sizing:border-box
            给元素border,padding不会改变它的width,height
             */
            box-sizing: border-box;
            border:10px solid black;
            padding:10px;
        }
    </style>
</head>
<body>
    <div>

    </div>
01.png

2. nav

 <style> 
/* inline-block实现导航 
技术要点:给父元素font-size:0; 
*/ 
{margin:0;padding:0} 
nav{
 line-height: 50px; 
background:deeppink; 
 font-size: 0;
height:50px;
 }
 .nav a{
color:#fff;
text-decoration: none; 
 display: inline-block; 
 font-size: 14px; 
 width:100px; 
text-align: center;} 
a:hover{ 
 background-color: pink;
 }
</style> 
 </head>
<body> 
<div class="nav">
 <a href="[#](#)">手机</a> 
<a href="[#](#)">平板</a>
<a href="[#](#)">电脑</a> 
</div>
01.png

3. float

<style>
        *{margin:0;padding:0}
        /* float的原理:相对于整个页面漂浮起来 */
        .one{
            width:100px;
            height:100px;
            background:red;
            float:right;
        }
        /* 如何清除float
        clear:both;
         */
        .two{
            clear:both;

            width:200px;
            height:200px;
            background:blue;
        }
    </style>
</head>
<body>
    <div class="one"></div>
    <div class="two"></div>
01.png
    <style>
        /* 
        如果前面的元素float,后面的元素没有清除float,那么就会受到前面元素的影响
         */
        .one,.two,.three{
            width:100px;
            height:100px;
           
            
        }
        .one{
            background: red;
            float:left;
        }
        .two{
            background:green;

        }
        .three{
            background:pink;
            float:right;
        }
    </style>
</head>
<body>
    <div class="one"></div>
    <div class="two"></div>
    <div class="three"></div>
01.png

4. float和父元素

    <style>
        /* 
        父元素不设置高度,子元素float,父元素的高度会坍塌
         */
         /* 
         如何让父元素重新获取高度
         1.给父元素 overflow:hidden;
         2.给父元素公共样式row
         .row:after{
             content:"";
             display:table;
             clear:both;
         }
          */
        .parent{
            width:400px;
            background: green;
            /* overflow: hidden; */
        }
        .child{
            width:200px;
            height:200px;
            background:red;
            float:left;
        }
        .two{
            width:400px;
            height:400px;
            background:blue;
        }
        .row:after{
            content:"";
            display: table;
            clear:both;
        }
    </style>
</head>
<body>
    <div class="parent  row">
        <div class="child"></div>
    </div>
    <!-- <div class="two">

    </div> -->
01.png
  <style>
        *{margin:0;padding:0}
        div{
            box-sizing: border-box;
        }
        .parent{
            width:1000px;margin-left: auto;margin-right: auto;
            background:deeppink;
        }
        .parent>div{
            float: left;width:240px;
            height:300px; border:1px solid #333;
            
        }
        .row:after{
            content:"";display: block;clear:both;
        }
        .parent>.child{
            margin-right:13.3333px;
        }
    </style>
</head>
<body>
    <div class="parent row">
        <div class="child"></div>
        <div class="child"></div>
        <div class="child"></div>
        <div></div>
    </div>

网友评论

      本文标题:day5

      本文链接:https://www.haomeiwen.com/subject/sbsvpftx.html