前端 HTML/CSS (九)

目录

浮动

设计的初衷:实现文字环绕效果。

原理:

  1. 父类高度塌陷,让跟随的内容可以和浮动的元素在一条线上。
  2. 块状盒子会和浮动元素重叠,但是块状元素中的行框盒子不会和浮动元素重叠。

规则:

  1. 考虑前面的元素。
  2. 只要是浮动的元素就会变成块状元素。
  3. 子元素浮动将会导致父元素高度塌陷。
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <style>
        div{
    
            border:1px solid green;
            font-size: 0;
        }
        div img{
    
            float:left;
        }
    </style>
</head>

<body>
    <div>
        <img src="./1111.jpg" />
    </div>

</body>

</html>

显示:
在这里插入图片描述
如果要放置高度塌陷尽量不要去设置height的值,否则一不小心会出现如下的情况:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <style>
        div {
    
            border: 1px solid green;
            font-size: 0;
            height: 350px;
        }

        div img {
    
            float: left;
        }
        p{
    
            margin:0px;
            border:1px solid green;
        }
    </style>
</head>

<body>
    <div>
        <img src="./1111.jpg" />
    </div>
    <p>
        We can also create a horrible user experience by making every property transition at a
        different rhythm, like this:
        Always remember that the transition-timing-function does not change the time it
        takes to transition properties: that is set with the transition-durationproperty. It
        just changes how the transition progresses during that set time. Consider the
        following:
    </p>

</body>

</html>

显示:
在这里插入图片描述

  1. 浮动元素四周的外边距不会折叠(上下边距不会折叠)
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <style>
        #f{
    
            width:500px;
            border:1px solid green;
        }
        #f .z{
    
            float
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值