角度如何在不向父组件中的td元素添加样式的情况下将子组件放置在中心位置

我有一个父子组件。父组件html是带有td元素的简单表。我想将子组件定位到td元素的中心。有没有更好的方法来将子组件定位为居中而不在父代的td中添加class ='centered'?

父组件html:

<table>
    <tr>
        <td class="centered">
            <app-courseformat-icon 
                [formatCode]="course.assignedFormat.formatCode"
                [tooltipText]="course.assignedFormat.formatName">
            </app-courseformat-icon>
        </td>  
    </tr>
</table>

app-courseformat-icon是子组件。

fxangin 回答:角度如何在不向父组件中的td元素添加样式的情况下将子组件放置在中心位置

尝试一下:

:host ::ng-deep app-courseformat-icon {
   text-align: center;
 }

请参阅此堆叠闪电战link

本文链接:https://www.f2er.com/3137193.html

大家都在问