zoukankan      html  css  js  c++  java
  • 清除float的方法

    清除浮动有两种方法:

    一种是加入clear:both:

    一种是BFC申明:

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>float的清除</title>
    </head>
    <style>
    .clearfix:after { content: ''; display: table; clear: both; }
    .clearfix { *zoom: 1; }
    </style>
    <body>
    1.
    <div style="background-color: #f5f5f5;" class="clearfix">
    <img src="http://img.mukewang.com/53d60af3000171a002560191.jpg" style="float:left;margin-bottom:100px;" >
    </div>
    <div style="margin-top: 100px;">本文字离图片的距离是?</div>
    2.
    <div style="background-color: #f5f5f5; overflow: hidden;">
    <img src="http://img.mukewang.com/53d60af3000171a002560191.jpg" style="float:left; margin-bottom: 100px;">
    </div>
    <div style="margin-top: 100px;">本文字离图片的距离是?</div><br><br><br>
    3.
    <div style="background-color: #f5f5f5;">
    <img src="http://img.mukewang.com/53d60af3000171a002560191.jpg" style="float:left;margin-bottom:100px;" >
    <div style="clear:both"></div>
    </div>
    <div style="margin-top: 100px;">本文字离图片的距离是?</div>

    4.
    <div style="background-color: #f5f5f5;" >
    <img src="http://img.mukewang.com/53d60af3000171a002560191.jpg" style="float:left;" >
    </div>
    <div style="margin-top: 100px;">本文字离图片的距离是?</div>
    <br>
    </body>
    </html>

    第一个div块是通过在css中增加删除float的类,注意的是应该在有浮动float的父元素加入。其中的.clearfix { *zoom: 1; }是为了兼容低级浏览器

    第二个div块是通过在加入float的DOM元素下面的加入style=“clear:both;”的同级元素来清除浮动

    第三个div块在浮动元素的父元素上加入overflow: hidden;样式也可清除浮动(overflow: hidden;使得包含图片的div自成BFC)

    第四个div没有清除浮动

  • 相关阅读:
    理解MapReduce计算构架
    熟悉HBase基本操作
    爬虫大作业
    熟悉常用的HDFS操作
    数据结构化与保存
    使用正则表达式,取得点击次数,函数抽离
    爬取校园新闻首页的新闻
    网络爬虫基础练习
    课后作业-阅读任务-阅读提问-5
    课后作业-阅读任务-阅读提问-4
  • 原文地址:https://www.cnblogs.com/wxw1314/p/5210420.html
Copyright © 2011-2022 走看看