How to set an element height same as width?

六眼飞鱼酱① 提交于 2020-05-26 08:05:09

问题


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}"    
>

回答1:


HTML:

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

DEMO

All the credit goes to @yurzui




回答2:


You need to use square.offsetWidth:

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

Link to working demo.



来源:https://stackoverflow.com/questions/46301181/how-to-set-an-element-height-same-as-width

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!