页面布局

1、固定盒子

使用20%的padding-bottom使得框等于其宽度的20%的高度。与视口宽度无关,子元素的div将保持其宽高比(100%/ 20%= 5:1)2

.container {
  height: 0;
  padding-bottom: 20%;
  position: relative;
}

.container div {
  border: 2px dashed #ddd;  
  height: 100%;
  left: 0;
  position: absolute;
  top: 0;
  width: 100%;
}

 2,

怎么让一个 div 水平垂直居中
< div class= "parent" >
< div class= "child" >< /div> < /div>
1、div.parent { 
    display: flex; 
    justify-content: center; 
    align-items: center; 
}

2、div.parent { 
    position: relative;
}
div.child { 
    position: absolute; 
    top: 50%; 
    left: 50%; 
    transform: translate(-50%, -50%); 
}
div.child {
    width: 50px;
    height: 10px; 
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -25px;
    margin-top: -5px;
}
.child{
    width:50px;
    height: 50px;
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom:0;
    margin: auto;
}

3、
.parent{
    display: grid;
    .child{
        justify-self: center;
        align-self: center;
    }
}

4、
.parent{
    font-size: 0;
    text-align: center;
    &::before {
        content: '',
        display: inline-block;
        width: 0;
        height: 100%;
        vertical-align: middle;
    }
    .child {
        display: inline-block;
        vertical-align: middle;
    }
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值