代码之家  ›  专栏  ›  技术社区  ›  Mukil Deepthi

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

  •  0
  • Mukil Deepthi  · 技术社区  · 5 年前

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

    父组件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

    0 回复  |  直到 5 年前
        1
  •  0
  •   Rajat Badjatya    5 年前

    试试这个:

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

    参考这篇闪电战 link