[CSS]垂直水平居中

约定不等于承诺〃 2022-11-26 04:58 465阅读 0赞

垂直水平居中两种实现方式:

  1. .box{

    1. width:200px;
    2. height: 200px;
    3. background: red;
    4. position: absolute;
    5. left:50%;
    6. top:50%;
    7. margin-left:-100px;
    8. margin-top:-100px;
    9. }
  2. .box{

    1. width:200px;
    2. height: 200px;
    3. background: blue;
    4. position: absolute;
    5. top:0;
    6. bottom:0;
    7. left:0;
    8. right:0;
    9. margin:auto;
    10. }

发表评论

表情:
评论列表 (有 0 条评论,465人围观)

还没有评论,来说两句吧...

相关阅读

    相关 CSS水平垂直居中

            在实际前端开发中,我们会遇到让一些元素居中的情况,如水平居中、垂直居中或者水平垂直居中等等。CSS的表示方法有很多,现在小编在这里总结一下,以便开发的时候可以快