【问题标题】:How to add styling to the root component dom element (angular selector component)如何为根组件 dom 元素添加样式(角度选择器组件)
【发布时间】:2020-05-19 04:53:27
【问题描述】:

我有以下组件:

// Typescript
@Component({
    selector: 'form-button',
    templateUrl: './form-button.component.html',
    styleUrls: ['./form-button.component.scss']
})
export class FormButtonComponent {}

//form-button.component.html
<div class="form-button-wrapper">
    <div class="content"></div>
</div>

//form-button.component.scss
.form-button-wrapper {
    width: 100%;
    height: 100%
}

在 html 中,将如下所示:

<head>...</head>
<body>
    ....
    <form-button>
         <div class="form-button-wrapper">
             <div class="content"></div>
         </div>
    </form-button>
    ....
</body>

我想为 &lt;form-button&gt; 而不是在 &lt;div class="form-button-wrapper"&gt; 中定义宽度和重量。

我该怎么做?

【问题讨论】:

标签: javascript css angular typescript sass


【解决方案1】:

是的,只需使用:host 选择器。它使您可以访问包装角元素。

//form-button.component.scss

:host {
 // insert your styles here
}

.form-button-wrapper {
    width: 100%;
    height: 100%
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-04
    • 1970-01-01
    • 1970-01-01
    • 2019-02-22
    • 2023-01-30
    • 1970-01-01
    • 2020-10-24
    • 1970-01-01
    相关资源
    最近更新 更多