英文:
how to select the two different class inside a parent class?
问题
.ja_jp .signup-container .signup-content .signup-choose-card-content .signup-choose-subtitle,
.ja_jp .signup-container .signup-content .signup-choose-card-content .signup-choose-list li {
font-family: "M+1C", Roboto, sans-serif;
}
英文:
I'm trying to select the class .signup-choose-subtitle
and .signup-choose-list li
in my parent class of signup-choose-card-content
to apply the font-family.
This is my code in css
.ja_jp
.signup-container
.signup-content
.signup-choose-card-content
.signup-choose-subtitle
.signup-choose-list li
{
font-family: "M+1C", Roboto, sans-serif;
}
and code in the html
<div class="signup-choose-card-content">
<p class="signup-choose-subtitle" translate="">Easy registration in 15 seconds! Play now!</p>
<p class="signup-choose-text-highlight">Lite</p>
<ul class="signup-choose-list">
<li translate="">No identity verification required</li>
<li translate="">Over 2,000 games</li>
</ul>
</div>
My goal is to overwrite the existing font-family: "Bahnschrift", Roboto, sans-serif;
to font-family: "M+1C", Roboto, sans-serif;
like this image:
答案1
得分: 1
Option 1:
目标特定元素,这些元素嵌套在.signup-choose-card-content
元素内。
.signup-choose-card-content .signup-choose-subtitle,
.signup-choose-card-content .signup-choose-list li {
font-family: "M+1C", Roboto, sans-serif;
}
查看下面的片段。
<div class="signup-choose-card-content">
<p class="signup-choose-subtitle" translate="">15秒内轻松注册!立即玩!</p>
<p class="signup-choose-text-highlight">Lite</p>
<ul class="signup-choose-list">
<li translate="">无需身份验证</li>
<li translate="">超过2,000款游戏</li>
</ul>
</div>
Option 2:
通过使用直接子代选择器(即>
),目标.signup-choose-card-content
元素内的所有元素,除了带有类signup-choose-text-highlight
的段落。
.signup-choose-card-content > :not(p.signup-choose-text-highlight) {
font-family: "M+1C", Roboto, sans-serif;
}
查看下面的片段。
<div class="signup-choose-card-content">
<p class="signup-choose-subtitle" translate="">15秒内轻松注册!立即玩!</p>
<p class="signup-choose-text-highlight">Lite</p>
<ul class="signup-choose-list">
<li translate="">无需身份验证</li>
<li translate="">超过2,000款游戏</li>
</ul>
</div>
英文:
Option 1
Target specific elements that are nested within the .signup-choose-card-content
element.
.signup-choose-card-content .signup-choose-subtitle,
.signup-choose-card-content .signup-choose-list li {
font-family: "M+1C", Roboto, sans-serif;
}
See the snippet below.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.signup-choose-card-content .signup-choose-subtitle,
.signup-choose-card-content .signup-choose-list li {
font-family: "M+1C", Roboto, sans-serif;
color: red;
}
<!-- language: lang-html -->
<div class="signup-choose-card-content">
<p class="signup-choose-subtitle" translate="">Easy registration in 15 seconds! Play now!</p>
<p class="signup-choose-text-highlight">Lite</p>
<ul class="signup-choose-list">
<li translate="">No identity verification required</li>
<li translate="">Over 2,000 games</li>
</ul>
</div>
<!-- end snippet -->
Option 2
Target all elements within the .signup-choose-card-content
element by using the direct child selector (i.e., >
) except paragraphs with the class signup-choose-text-highlight
.
.signup-choose-card-content > :not(p.signup-choose-text-highlight) {
font-family: "M+1C", Roboto, sans-serif;
}
See the snippet below.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.signup-choose-card-content > :not(p.signup-choose-text-highlight) {
font-family: "M+1C", Roboto, sans-serif;
color: red;
}
<!-- language: lang-html -->
<div class="signup-choose-card-content">
<p class="signup-choose-subtitle" translate="">Easy registration in 15 seconds! Play now!</p>
<p class="signup-choose-text-highlight">Lite</p>
<ul class="signup-choose-list">
<li translate="">No identity verification required</li>
<li translate="">Over 2,000 games</li>
</ul>
</div>
<!-- end snippet -->
答案2
得分: 0
根据您的描述,您可能希望这样做(我添加了边框属性以在开发过程中更好地可见):
.signup-choose-card-content > .signup-choose-list li,
.signup-choose-card-content > .signup-choose-subtitle {
border: 4px solid red;
}
使用子组合器可以选择类/元素等的直接子元素,参见这里:https://developer.mozilla.org/en-US/docs/Web/CSS/Child_combinator
英文:
According to your description you would probably want it this way (I added the border-property for better visibility druing development):
.signup-choose-card-content > .signup-choose-list li,
.signup-choose-card-content > .signup-choose-subtitle {
border: 4px solid red ;
}
With the child combinator you can select direct children of classes/elements etc, see here: https://developer.mozilla.org/en-US/docs/Web/CSS/Child_combinator
> The child combinator (>) is placed between two CSS selectors.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论