2-10 编程练习

来源:2-10 编程练习

汪晓歌

2018-11-03 15:42:50

这个为什么父元素要写个相对定位呀,我不是很明白。我是参考人家做出来的。老师这个定位这个章节怎么看的不是很明白呀?

<!DOCTYPE html>

<html>

<head>

  <meta charset="UTF-8">

  <title>Document</title>

  <style>

    /*完善下列代码*/

    .per{

     width: 300px;

     height: 300px;

     background: red;

     margin-left:200px;

     margin-top: 200px;

     position:relative;

   }


   .son{

     width: 100px;

     height: 100px;

     background: blue;

     position:absolute;

     left:0px;

     right:0px;

     bottom:0px;

     top:0px;

     margin:auto auto;

   }

  </style>

</head>

<body>

  <div class="per">

    <div class="son"></div>

  </div>

</body>

</html>  


写回答

1回答

樱桃小胖子

2018-11-04

给父元素设置相对定位是需要让子元素设置了绝对定位后,相对于父级元素进行定位,从而实现练习中的效果。祝学习愉快!

0

0 学习 · 36712 问题

查看课程

相似问题