如何在父类中选择两个不同的子类?

huangapple go评论52阅读模式
英文:

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: &quot;M+1C&quot;, 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: &quot;M+1C&quot;, Roboto, sans-serif;
  color: red;
}

<!-- language: lang-html -->

&lt;div class=&quot;signup-choose-card-content&quot;&gt;
   &lt;p class=&quot;signup-choose-subtitle&quot; translate=&quot;&quot;&gt;Easy registration in 15 seconds! Play now!&lt;/p&gt;
   &lt;p class=&quot;signup-choose-text-highlight&quot;&gt;Lite&lt;/p&gt;

   &lt;ul class=&quot;signup-choose-list&quot;&gt;
       &lt;li translate=&quot;&quot;&gt;No identity verification required&lt;/li&gt;
       &lt;li translate=&quot;&quot;&gt;Over 2,000 games&lt;/li&gt;
   &lt;/ul&gt;
&lt;/div&gt;

<!-- end snippet -->

Option 2

Target all elements within the .signup-choose-card-content element by using the direct child selector (i.e., &gt;) except paragraphs with the class signup-choose-text-highlight.

.signup-choose-card-content &gt; :not(p.signup-choose-text-highlight) {
  font-family: &quot;M+1C&quot;, Roboto, sans-serif;
}

See the snippet below.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.signup-choose-card-content &gt; :not(p.signup-choose-text-highlight) {
  font-family: &quot;M+1C&quot;, Roboto, sans-serif;
  color: red;
}

<!-- language: lang-html -->

&lt;div class=&quot;signup-choose-card-content&quot;&gt;
   &lt;p class=&quot;signup-choose-subtitle&quot; translate=&quot;&quot;&gt;Easy registration in 15 seconds! Play now!&lt;/p&gt;
   &lt;p class=&quot;signup-choose-text-highlight&quot;&gt;Lite&lt;/p&gt;

   &lt;ul class=&quot;signup-choose-list&quot;&gt;
       &lt;li translate=&quot;&quot;&gt;No identity verification required&lt;/li&gt;
       &lt;li translate=&quot;&quot;&gt;Over 2,000 games&lt;/li&gt;
   &lt;/ul&gt;
&lt;/div&gt;

<!-- 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 &gt; .signup-choose-list li,
.signup-choose-card-content &gt; .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.

huangapple
  • 本文由 发表于 2023年6月5日 16:38:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76404734.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定