码迷,mamicode.com
首页 > Web开发 > 详细

CSS浮动

时间:2016-05-13 15:41:52      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:css浮动

一、浮动

    left    元素向左浮动

    right    元素向右浮动

    none    元素不浮动

    inherit    从父级继承浮动属性

#fd{
    width: 100px;
    height: 100px;
    background-color: red;
    float: left;
}

#sd{
    width: 100px;
    height: 100px;
    background-color: blue;
    float: left;
}

#td{
    width: 100px;
    height: 100px;
    background-color: green;
    float: left;
}

#container{
    width: 400px;
    height: 500px;
    background-color: darkgray;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>浮动</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <div id="container">
        <div id="fd"></div>
        <div id="sd"></div>
        <div id="td"></div>
    </div>

</body>
</html>


二、clear属性

    去掉浮动属性(包括继承来的属性)

    left、right    去掉元素向左、向右浮动

    both    左右两侧均去掉浮动

    inherit    从父级继承来clear的值

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>浮动</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <div id="container">
        <div id="fd"></div>
        <div id="sd"></div>
        <div id="td"></div>
        <div id="text">HelloWorld!</div>
    </div>

</body>
</html>
#fd{
    width: 100px;
    height: 100px;
    background-color: red;
    float: left;
}

#sd{
    width: 100px;
    height: 100px;
    background-color: blue;
    float: left;
}

#td{
    width: 100px;
    height: 100px;
    background-color: green;
    float: left;
}

#container{
    width: 280px;
    height: 500px;
    background-color: darkgray;
}

#text{
    clear: left;
}









CSS浮动

标签:css浮动

原文地址:http://11317783.blog.51cto.com/11307783/1772841

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!