绝对定位练习

绝对定位可以让我们的网页处于一个固定位置,这次教大家用网页制作一个笑脸(迫真),以下是原代码

<!doctype html>
<html>
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绝对定位</title>
    <style>

      #div1{
                width: 75px;
                height: 75px;
                background-color: rgb(2, 17, 2);
                position: absolute;
                left: 50px;
                top: 100px;
                /* position: absolute; */
                /* left: 20px; 
                top: 20px;  */
          }  
      
      #div2{
            width: 75px;
            height: 75px;
            background-color: rgb(2, 17, 2);
            position: absolute;
            left: 250px;
            top: 100px;
            /* position: absolute; */
            /* left: 20px; 
            top: 20px;  */
          } 

      #div3{
            width: 300px;
            height: 50px;
            background-color: rgb(3, 3, 63);
            position: absolute;
            left: 200px;
            top: 250px;
            /* position: absolute; */
            /* left: 20px; 
            top: 20px;  */
          } 
          
    article{
            width: 500px;
            height: 500px;
            background-color: gray;

            /* position: absolute;
            left: 100px;
            top: 100px; */
        }

    </style>

  </head>

  <body>

    <article>
        <div id="div1">div1</div>
        <div id="div2">div2</div>
        <div id="div3">div3</div>
    </article>

  </body>
</html>

 1,首先,我们在body栏设置一个3个div标签,用作表情的眼睛跟嘴巴,如下所示

  <body>

    <article>
        <div id="div1">div1</div>
        <div id="div2">div2</div>
        <div id="div3">div3</div>
    </article>

  </body>

2,我们可以给div以及article标签设置大小,背景颜色,以及位置,如下所示

    <style>

      #div1{
                width: 75px;
                height: 75px;
                background-color: rgb(2, 17, 2);
                position: absolute;
                left: 50px;
                top: 100px;
                /* position: absolute; */
                /* left: 20px; 
                top: 20px;  */
          }  
      
      #div2{
            width: 75px;
            height: 75px;
            background-color: rgb(2, 17, 2);
            position: absolute;
            left: 250px;
            top: 100px;
            /* position: absolute; */
            /* left: 20px; 
            top: 20px;  */
          } 

      #div3{
            width: 300px;
            height: 50px;
            background-color: rgb(3, 3, 63);
            position: absolute;
            left: 200px;
            top: 250px;
            /* position: absolute; */
            /* left: 20px; 
            top: 20px;  */
          } 
          
    article{
            width: 500px;
            height: 500px;
            background-color: gray;

            /* position: absolute;
            left: 100px;
            top: 100px; */
        }

    </style>

以下是效果图,我们也可以把绝对定位应用到想要的主题上,希望能帮到你!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值