简体   繁体   English

嵌套的H3在CSS中不起作用

[英]Nested h3 in scss not working

I'm trying to change the margins of an h3 tag using scss in Angular. 我正在尝试使用Angular中的scss更改h3标签的边距。 The scss is working but when I nest h3 inside a div tag it does not work. 该scss在工作,但是当我将h3嵌套在div标签中时,它不起作用。

Can someone point me in the right direction? 有人可以指出我正确的方向吗?

SCSS SCSS

// Does not work
.subTitle {
    h3 {
        margin-top: 1px;
    }
}

// Works
h3 {
    margin-top: 1px;
}

HTML HTML

<div class="row">
    <div *ngFor="let post of allPosts" class="col-md-12 blogPost">
        <div id="title"><h1>{{post.title}}</h1></div>
        <div id="subTitle"><h3>{{post.subTitle}}</h3></div>
        <div id="blogContent"><p>{{post.content}}</p></div>
    </div>
</div>

JS JS

This is because your markup sets the id , and you CSS targets a class using the . 这是因为您的标记设置了id ,而CSS使用定位了一个类. syntax. 句法。 Use #subTitle in CSS, or change the markup to use class=subTitle . 在CSS中使用#subTitle ,或将标记更改为使用class=subTitle

You should use a class because you're inside the *ngFor , and multiple elements should not have the same ID. 您应该使用一个类,因为您位于*ngFor ,并且多个元素不应具有相同的ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM