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

CSS样式-浮动

时间:2021-02-27 13:17:54      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:doc   包括   title   常见   width   bsp   过程   inf   round   

浮动,就是使元素脱离标准流,移动到其父元素指定的位置的过程,包括float: left  float: right;

浮动常见的问题:

1.浮动的子元素无法超出父元素的范围;

<head>
    <style type="text/css">
        #father {
            width: 200px;
            height: 200px;
            background-color:#f00;
        }
        #son {
            width: 100px;
            height: 100px;
            background-color: #0f0;
            float:right;
        }
    </style>
</head>
<body>
    <div id="father">
        <div id="son"></div>
    </div>
</body>

 技术图片

 

 

2.如果父元素设置padding,那么子元素无法超出父元素的padding;

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style type="text/css">
        #father {
            width: 200px;
            height: 200px;
            background-color:#f00;
            padding: 10px;
        }
        #son {
            width: 100px;
            height: 100px;
            background-color: #0f0;
            float:right;
        }
    </style>
</head>
<body>
    <div id="father">
        <div id="son"></div>
    </div>
</body>
技术图片

 

 

 

CSS样式-浮动

标签:doc   包括   title   常见   width   bsp   过程   inf   round   

原文地址:https://www.cnblogs.com/Friday1/p/14454068.html

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