【问题标题】:Resizing height & width of the div in percentage not pixel by using angular 5使用角度 5 以百分比而不是像素调整 div 的高度和宽度
【发布时间】:2018-07-24 08:52:17
【问题描述】:

我是 Angular 5 的新手。我必须使用 Angular 5 以百分比形式调整 div 的高度和宽度。请帮助我实现此功能。

【问题讨论】:

  • 在你的 .ts percent:number=30;在 .html [style.height]="{{percent+%}}"
  • 发布您的代码。到目前为止你做了什么

标签: javascript angular


【解决方案1】:

您可以轻松做到这一点。

<p [style.width.%]="someValue"> ... </p>
<p [style.height.%]="someValue"> ... </p>

ref

【讨论】:

    【解决方案2】:

    您必须在 .css 文件中声明 css 属性。

    例如:

    div {
        height: 200px;
        width: 50%;
        background-color: powderblue;
    }
    

    【讨论】:

      【解决方案3】:

      最好在 css/ .ts 文件中使用它

      @Component({
        selector: 'your-selector',
        styles: [`   
            .change-hight-width{
              height: 200px;
              width:200px;
            }   
        `]
      //rest of the code
          })
      

      在html中

      <div [ngClass]="'change-hight-width'">
      

      【讨论】:

        猜你喜欢
        • 2012-12-03
        • 2014-06-07
        • 1970-01-01
        • 2014-03-05
        • 1970-01-01
        • 1970-01-01
        • 2017-08-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多