0

我在我的 css 中使用 .section-title h1 并将文本对齐到中心,但它不起作用但如果我只使用 h1 来对齐文本,它肯定会起作用。

<div id="section-title">
    <h1>GET IN TOUCH</h1>
    <p>Make sure to subscribe to this channel</p>
</div>

对于我尝试过的 CSS

h1.section-title {
    text-align: center;
}

.section-title h1
{
    text-align: center;
}
4

3 回答 3

1

回答:

而不是使用类选择器替换为 ID 选择器(#)。

#section-title h1
{
    text-align: center;
}
于 2019-10-29T07:22:40.283 回答
0

请试试这个

'section-title' 是 H1 的 ID。所以请使用“#”而不是“。” 在你的 CSS

h1#section-title
{
    text-align: center;
}
<div>
    <h1 id="section-title">GET IN TOUCH</h1>
    <p>Make sure to subscribe to this channel</p>
</div>

于 2019-10-29T06:51:57.137 回答
0

有两种选择:

Option1 使用 div 类:

<div class="section-title">
    <h1>GET IN TOUCH</h1>
    <p>Make sure to subscribe to this channel</p>
</div>
.section-title h1 
{
    text-align: center;
}

或使用 h1 ID 的选项 2:

<div>
    <h1 id="section-title">GET IN TOUCH</h1>
    <p>Make sure to subscribe to this channel</p>
</div>

h1#section-title
{
    text-align: center;
}
于 2019-10-29T06:47:22.547 回答