zoukankan      html  css  js  c++  java
  • CSS清浮动

    1.给父级也加浮动(内容一旦浮动就意味着脱离文档流,而父级始终保持原有状态,所以必须同时浮动)

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <style>
    .box{ width:300px;margin:0 auto;border:10px solid #000; float:left;}
    .div{ width:200px;height:200px;background:red;float:left;}
    /*
    清浮动
    1.给父级也加浮动(不居中了)
    */
    </style>
    </head>
    <body>
    <div class="box">
    <div class="div"></div>
    </div>
    </body>
    </html>

    2.给父级加display:inline-block

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <style>
    .box{ width:300px;margin:0 auto;border:10px solid #000; display:inline-block;}
    .div{ width:200px;height:200px;background:red;float:left;}
    /*
    清浮动
    2.给父级加display:inline-block
    */
    </style>
    </head>
    <body>
    <div class="box">
    <div class="div"></div>
    </div>
    </body>
    </html>
    View Code

    3.加<div class="clear"></div>

    .clear{ height:0px;font-size:0;clear:both;}但是在ie6下,块元素有最小高度,即当height<19px时,默认为19px,解决方法:font-size:0;或overflow:hidden;
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <style>
    .box{ width:300px;margin:0 auto;border:10px solid #000;}
    .div{ width:200px;height:200px;background:red;float:left;}
    .clear{ height:0px;font-size:0;clear:both;}
    /*
    清浮动
    1.给父级也加浮动
    2.给父级加display:inline-block
    3.在浮动元素下加<div class="clear"></div>
    .clear{ height:0px;font-size:0;clear:both;}
    */
    </style>
    </head>
    <body>
    <div class="box">
    <div class="div"></div>
    <div class="clear"></div>
    </div>
    </body>
    </html>
    View Code

    4.在浮动元素下加<br clear="all">

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <style>
    .box{ width:300px;margin:0 auto;border:10px solid #000;}
    .div{ width:200px;height:200px;background:red;float:left;}
    /*
    清浮动
    4.在浮动元素下加<br clear="all"/>
    */
    </style>
    </head>
    <body>
    <div class="box">
    <div class="div"></div>
    <br clear="all"/>
    </div>
    </body>
    </html>
    View Code

    5.伪类清除浮动

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <style>
    .box{margin:0 auto;border:10px solid #000;}
    .div{ width:200px;height:200px;background:red;float:left;}
    .clear{zoom:1;}//解决IE6问题
    .clear:after{content:""; display:block;clear:both;}
    /*
    清浮动
    5. 给浮动元素的父级加{zoom:1;}
    :after{content:""; display:block;clear:both;}
    **在IE6,7下浮动元素的父级有宽度就不用清浮动
    haslayout 根据元素内容的大小 或者父级的父级的大小来重新的计算元素的宽高
    display: inline-block
    height: (任何值除了auto)
    float: (left 或 right)
     (任何值除了auto)
    zoom: (除 normal 外任意值)
    */
    </style>
    </head>
    <body>
    <div class="box clear">
    <div class="div"></div>
    </div>
    </body>
    </html>
    View Code

    6.给浮动元素父级加overflow:hidden;

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <style>
    .box{ width:300px;border:1px solid #000;overflow:hidden;}
    .div1{ width:260px;height:400px;background:Red;float:left;}
    </style>
    </head>
    <body>
    <div class="box">
    <div class="div1"></div>
    </div>
    </body>
    </html>
    View Code
  • 相关阅读:
    Wwise音频解决方案概述
    图形学中的几何光学理论与视觉现象
    Visual Studio 2015 Tools for Unity使用基础
    C++编译器优化技术:RVO、NRVO和复制省略
    【ElasticSearch】 ElasticSearch基本概念和RESTful API(四)
    【ElasticStack】入门介绍(三)
    【Java】开发一个Java-SDK
    【Java】Maven 打包可运行jar包
    【SpringBoot】Spring Boot Admin 微服务应用监控
    【Java面试题】方法的参数传递机制
  • 原文地址:https://www.cnblogs.com/littlewriter/p/6051357.html
Copyright © 2011-2022 走看看