【HTML】元素定位

一、 开启定位

        第一步position定位的方式

        第二步定义偏移量

        方向:水平方向 left/right

                  竖直方向 top/bottom

                 relative 相对定位 相当于该元素在文件流中的位置

                static 默认值

                absolute 绝对定位 相对的位置不一样 相对于开启了定位的父元素。如果父元素没有开启定位,依次往上找父元素的父元素,直到body为止u

                fixed 固定定位

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

        #box1{
            height: 280px;
            width: 300px;
          margin: 0 auto;
          position: relative;
          top: 200px;
          border: 1px solid beige;
         
        }
        #box2{
            height: 150px;
            width: 180px;
           
            position: absolute;
             left: 80px;
             top: 100px;
            border: 1px solid beige;
   
        }
        #box3{
            height: 60px;
            height: 50px;
            position: absolute;
            bottom: 110px;
            left: 100px;
        }
        .wen{
            text-align: center;
            
            
            font-size: 20px;
        }
        .w{
            border-bottom: 1px gray dashed;
            margin-top:  10px;
            margin-bottom: 10px;
        }
        .ig{
            color: coral;
        }
        .ij{
            position: absolute;
            bottom: 14px;
            color:white;
        }
    </style>
</head>
<body>
        </div>
        <div id="box1">
          <p class="wen"> 前端开发</p> 
          <div  class="w">

          </div>
         <div id="box2">
            <img src="images\01.jpg" >
            <p>Web前端学习</p>
            <p class="ig"> 你就是未来的前端工程师</p>
            <div id="box3">
                <img src="images\label.png" alt="">
                <p class="ij">点播</p>
            </div>
         </div>
    </div>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值