小编典典

高度等于动态宽度(CSS流体布局)

html

是否可以将宽度设置为相同的高度(比率1:1)?

+----------+
| body     |
| 1:3      |
|          |
| +------+ |
| | div  | |
| | 1:1  | |
| +------+ |
|          |
|          |
|          |
|          |
|          |
+----------+

CSS

div {
  width: 80%;
  height: same-as-width
}

阅读 743

收藏
2020-05-10

共1个答案

小编典典

使用jQuery,您可以通过以下方式实现此目的

var cw = $('.child').width();
$('.child').css({'height':cw+'px'});
2020-05-10