css实现正方形div的3种方式
2016-05-24 16:33
477 查看
1.CSS3 vw 单位
1vw = 1% viewport width
2.padding-bottom
3,padding-bottom+:after+absolute
利用vw,margin,padding
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%; }
利用vw,margin,padding
相关文章推荐
- Web布局连载——两栏固定布局(五)
- [div+css]晒晒最新制作专题推广页模板
- 盒子模型
- CSS选择器
- CSS样式优先权
- [css] line-height 百分比单位和数值单位的区别
- Apple官网研究之使用Justify布局导航
- 关于前端的思考与感悟
- rem : web app适配的秘密武器
- 设计更快的网页(三):字体和 CSS 调整
- 纯CSS制作的新闻网站中的文章列表
- 10条影响CSS渲染速度的写法与使用建议第1/3页
- BS项目中的CSS架构_仅加载自己需要的CSS
- 很不错的 CSS Hack 又学了一招
- 发一个css比较清爽的写法
- CSS expression控制图片自动缩放效果代码[兼容 IE,Firefox]
- css布局网页水平居中常用方法
- CSS经典技巧十则第1/2页
- css 兼容性问题this.style.cursor=''hand''