css高度与width相同 [英] css height same as width

查看:1082
本文介绍了css高度与width相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的css文件中做下一个技巧,因此width = height而不设置像素。我想这样做,无论浏览器的分辨率,在这两个维度上有相同的值。

I would like to do the next trick in my css file so that width=height without setting pixels. I want to do this so whatever the resolution of the browser is, to have same values on these two dimensions.

#test{
width: 20%;
height: (same as width);
}

可能吗?

推荐答案

这种效果可以用 padding margin 该值相对于元素的容器的 width

That effect can be just faked with padding or margin since that values are relative to the width of the container for the element.

div {
  background:orange;
  width:20%;
  padding-top:20%;
}

检查此http://jsfiddle.net/4z8PT/

这篇关于css高度与width相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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