纯CSS解决方案 - 方形元素? [英] Pure CSS Solution - Square Elements?

查看:98
本文介绍了纯CSS解决方案 - 方形元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个具有相对宽度(例如 width:50%)的< div> ,是否有一个简单的方法使它与它的高度相同的宽度,而不诉诸JavaScript?

If I have a <div> with a relative width (such as width: 50%), is there a simple way to make it have the same width as it does height without resorting to JavaScript?

推荐答案

实际上可以实现它与这个整洁窍门我在
此博客

It is actually possible to achieve it with this neat trick i found at this blog

#square {
   width: 100%;
   height: 0;
   padding-bottom: 100%;
}

希望有助于

这篇关于纯CSS解决方案 - 方形元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆