zoukankan      html  css  js  c++  java
  • 如何让一个div水平垂直居中

     1 div {
     2 position: relative / fixed; /* 相对定位或绝对定位均可 */
     3 width:500px;
     4 height:300px;
     5 top: 50%;
     6 left: 50%;
     7 margin-top:-150px;
     8 margin-left:-250px;
     9  外边距为自身宽高的一半 */
    10 background-color: pink; /* 方便看效果 */
    11  }
    12 
    13 .container {
    14 display: flex;
    15 align-items: center; /* 垂直居中 */
    16 justify-content: center; /* 水平居中 */
    17  
    18 }
    19 .container div {
    20 width: 100px; /* 可省 */
    21 height: 100px; /* 可省 */
    22 background-color: pink; /* 方便看效果 */
    23 }  
    世界上没有什么偶然,有的只有必然。——壹原侑子
  • 相关阅读:
    kvm virtio
    GPU 线程块/线程束
    ubuntu source
    React
    分布式系统
    honpeyhonepy
    css是干什么的
    bootstrap中的横的列
    数据安全之 alert logic
    viewset的使用的方法
  • 原文地址:https://www.cnblogs.com/liazhimao/p/13838734.html
Copyright © 2011-2022 走看看