前端-浮动布局-定位布局-过渡动画

本文深入探讨了前端布局中的浮动布局,包括浮动案例;接着详细讲解了不同类型的定位技术,如固定定位、绝对定位和相对定位;最后,通过定位动画案例展示了如何在实践中实现动态效果。
摘要由CSDN通过智能技术生成

浮动布局
what|why:让块级(block)标签在父级的宽度限制下同行显示,一行显示不下,自动换行
注:要到达一行显示个数固定,一定要固定父级的宽度

语法:
子级 {
   
	float: left|right;
}

问题:子级不再撑开父级高度(不完全脱离文档流)
脱离文档流: => 层次结构会上移,覆盖有位置重叠且没脱离文档流的标签
不完全:浮动布局后,可以重新让子级撑开父级高度

清浮动:让不完全脱离文档流的子级重新撑开父级的高度,这种做法就叫做清浮动

语法:
父级:after {
   
	content: "";
	dislpay: block;
	clear: both;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>浮动布局</title>
    <link rel="stylesheet" href="css/reset.css">
    <style>
        .div {
    
            width: 200px;
            height: 200px;
            background-color: yellow;
            margin-right: 10px;
            /*float 浮动*/
            float: right;
        }
    </style>
    <style>
        .ul1 {
    
            background-color: pink;
            width: 600px;
            margin: 0 auto;
        }
        .ul1 li {
    
            width: 200px;
            height: 60px;
        }
        .ul1 li:nth-child(2n) {
    
            background-color: orange;
        }
        .ul1 li:nth-child(2n - 1) {
    
            background-color: red;
        }

        /*谁们需要同行排列, 谁们就用浮动布局处理*/
        .ul1 li {
    
            float: left;
            /*float: right;*/
        }
        /*谁的高度没有被浮动子级撑开, 谁来清浮动*/
        .ul1:after {
    
            content: "";
            display: block;
            clear: both;
        }


        .bro {
    
            width: 50px;
            height: 50px;
            background-color: black;
        }
    </style>
</head>
<body>

<!--<div class="div"></div>-->

<ul class="ul1">
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
</ul>
<div class="bro"></div>

<!--了解-->
<!--:after | :before 伪类 -> 内容-->
<style>
    .box:after {
    
        /*display: block;*/
        content: "000";
    }
    .box:before {
    
        /*display: block;*/
        content: "***";
    }
</style>
<div class="box">123</div>
</body>
</html>
浮动案例
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>浮动案例</title>
    <link rel="stylesheet" href="css/reset.css">
    <style>
        .ul1 {
    
            width: 825px;
            margin: 0 auto;
            background-color: black;
        }
        .ul1 li {
    
            width: 200px;
            height: 120px;
            background-color: red;
            margin-right: 15px;
            float: left;
        }
        .ul1 li:first-child {
    
            width: 180px;
        }
        .ul1 li:last-child {
    
            margin-right: 0;
        }

        .ul1:after {
    
            content: "";
            display: block;
            clear: both;
        }
    </style>
    <style>
        .box1 {
    
            background-color: pink;
            /*line-height: 50px;*/
            padding: 10px 0;
        }
        .box1:after {
    
            content: "";
            display: block;
            clear: both;
        }
        .box1 h3 {
    
            float: left;
        }
        .box1 ul {
    
            float: right;
        }
        /*浮动的盒子宽度不再获取父级宽度,由内容撑开*/
        .box1 li {
    
            float: left
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值