宽高保持不变,你参考下,内容要绝对定位
css_square.main {
width: 600px;
}
.rect1 {
position: relative;
width: 50%;
background: #f30;
padding-bottom: 50%;
}
.rect1 > .inner,
.rect2 > .inner {
padding: 100px;
position: absolute;
top: 50%;
left: 50%;
background-color: #0ac;
-webkit-transform: translate(-50%, -50%);
}
.rect2 > .inner {
background-color: #0cc;
}
.rect2 {
position: relative;
width: 50%;
background: #f30;
}
.rect2:before {
content: "";
display: block;
padding-top: 100%;
width: 100%;
background: #08c;
}
纯CSS实现正方形布局
document.querySelector('#range').addEventListener('change', function(e) {
document.querySelector('.main').style.width = 600 + this.value/1 + 'px'
})
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- zicool.com 版权所有 湘ICP备2023022495号-2
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务