首页 > Web开发 > 详细

css实现正方形div的3种方式

时间:2016-09-22 19:31:45      阅读:216      评论:0      收藏:0      [点我收藏+]

1.CSS3 vw 单位
1vw = 1% viewport width

<div class="vw">hello,viewport</div>
.vw {
        width: 50%;
        height: 50vw;
        background: #ccc;
    }

 

2.padding-bottom

<div class="placeholder"></div>
 .placeholder {
        width: 100%;
        padding-bottom: 100%;/* padding百分比相对父元素宽度计算 */
        height: 0;//避免被内容撑开多余的高度
    }

 

3,padding-bottom+:after+absolute

<div class="square">
    <div class="content">
        Hello!
    </div>
</div>
.square {
    width: 50%;
    background: #ccc;
}

.square:after {
    content: "";
    display: block;
    padding-bottom: 100%;
}

.content {
    position: absolute;
    width: 100%;
    height: 100%;
}

 

css实现正方形div的3种方式

原文:http://www.cnblogs.com/wwlhome/p/5897320.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!