如何设置元素的高度和宽度相同? [英] How to set an element height same as width?

查看:357
本文介绍了如何设置元素的高度和宽度相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我设置元素高度和宽度相同的最佳方法是什么?此外,它还应根据Web浏览器分辨率的变化进行自动缩放.是否只有HTML模板才能做到这一点?像这样:

Can somebody tell me what is the best way to set height of element same as width? Also it should had auto-scaling according to web browser resolution changes. Is there a wato to that with only html template? Something like:

<div 
    class="tile"
    #square
    [ngStyle]="{'height.px': square.width}"    
>

推荐答案

HTML:

  <div #div (window:resize)="0" [ngStyle]="{'height.px': div.offsetWidth }">

演示

所有功劳归功于@yurzui

All the credit goes to @yurzui

这篇关于如何设置元素的高度和宽度相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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