页面设置问题

来源:3-4 编程练习

慕慕9452826

2018-12-04 23:59:33

1、设置 tu 的浮动后,h2设置不设置代码页面效果都一样,为什么呢?

<!DOCTYPE html>
<html>
<head>
        <!-- 此处编写样式 -->
        <style>
           .kuang{
            width: 800px;/*宽度*/
            height: 360px;/*高度*/
            margin-top: 30px;/*上边距*/
            margin-left: 30px;/*左边距*/
            border: 2px green dashed;/*设置样式,边框、颜色、虚线 */
            padding:10px;/*填充*/
            color: both;
           }
          .h1{
               width: 800px;
               height: 180px;
               margin-left: 20px;
             }
          .tu{
            width: 260px;
            height: 135px;
            float: left;
          }
          .h2{
            width: 800px;
            height: 180px;
            margin-left: 20px;
          }
        </style>
</head>
<body>  
        <!-- 此处写代码 -->
        <div class="kuang">
            <div class="h1">
                 <div class="tu"><img src="http://climg.mukewang.com/590fe9770001e63102400135.jpg"><p>欢迎来到慕课网学习新知识</p></div>
                 <div class="tu"><img src="http://climg.mukewang.com/590fe97d00011bda02400135.jpg"><p>欢迎来到慕课网学习新知识</p></div>
                 <div class="tu"><img src="http://climg.mukewang.com/590fe982000150ba02400135.jpg"><p>欢迎来到慕课网学习新知识</p></div>
            </div>   
            <div class="h2">
                <div class="tu"><img src="http://climg.mukewang.com/590fe9770001e63102400135.jpg"><p>欢迎来到慕课网学习新知识</p></div>
                 <div class="tu"><img src="http://climg.mukewang.com/590fe97d00011bda02400135.jpg"><p>欢迎来到慕课网学习新知识</p></div>
                 <div class="tu"><img src="http://climg.mukewang.com/590fe982000150ba02400135.jpg"><p>欢迎来到慕课网学习新知识</p></div>
            </div>    
        </div>  
</body>
</html>

写回答

1回答

好帮手慕查理

2018-12-05

您好,当设置tu之后h2不设置宽高依旧没问题,是因为h1的宽高已确定,且tu设置了浮动,那么当图片浮动时,上面的位置已经固定,那么就会在h1之后继续浮动。因此不设置宽高依旧是成功的。祝学习愉快!

0

0 学习 · 4928 问题

查看课程