请问可以用margin实现居中吗?我试了没有作用

来源:2-10 编程练习

Ace_____

2017-07-06 16:15:57

<!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: 100px;

     top: 100px;

   }

  </style>

</head>

<body>

  <div class="per">

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

  </div>

</body>

</html>


写回答

1回答

樱桃小胖子

2017-07-06

在per里面设置 margin:200px auto 0;即可

.per{
     width: 300px;
     height: 300px;
     background: red;
     /*margin-left:200px;
     margin-top: 200px;*/
     margin:200px auto 0;
     position: relative;
   }

希望可以帮到你!

0
hce_____
h 非常感谢!
h017-07-07
共3条回复

0 学习 · 36712 问题

查看课程