if i add font-weight to a paragraph, the text inside <span> changes to. what is the reason? added the code

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

if i add font-weight to a paragraph, the text inside <span> changes to. what is the reason? added the code

问题

<!-- 开始代码段: js 隐藏: false 控制台: true Babel: false -->

<!-- 语言: lang-css -->
.tweet {
  width: 600px;
  line-height: 25px;
  font-weight: 800;
  margin-bottom: 20px;
  color: rgb(0, 0, 0);
}

.twitter-handle {
  color: rgb(29, 155, 240);
}

<!-- 语言: lang-html -->
<p class="tweet">
  作为网页开发者,您希望使您的项目易于使用和导航。
</p>

<p class="tweet">
  在这里 <span class="twitter-handle">@chp_it</span> 概述了新开发者应具备的顶级技能。
</p>

<!-- 结束代码段 -->
英文:

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

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

.tweet {
  width: 600px;
  line-height: 25px;
  font-weight: 800;
  margin-bottom: 20px;
  color: rgb(0, 0, 0);
}

.twitter-handle {
  color: rgb(29, 155, 240);
}

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

&lt;p class=&quot;tweet&quot;&gt;
  As a web developer, you&#39;ll want to make your projects easy to use and navigate around.
&lt;/p&gt;

&lt;p class=&quot;tweet&quot;&gt;
  Here &lt;span class=&quot;twitter-handle&quot;&gt;@chp_it&lt;/span&gt; outlines the top skills new developers should have.
&lt;/p&gt;

<!-- end snippet -->

tried to bold the tweet text, instead the code gets applied for the <span> @chp_it tag too.

答案1

得分: 2

因为您在&lt;p&gt;元素中为所有内容设置了样式,而&lt;span&gt;位于&lt;p&gt;元素中。

如果您想为&lt;span&gt;设置特定样式,您可以像为&lt;p&gt;元素一样为它添加样式规则。例如,要重置font-weight

.tweet {
  width: 600px;
  line-height: 25px;
  font-weight: 800;
  margin-bottom: 20px;
  color: rgb(0, 0, 0);
}

.twitter-handle {
  color: rgb(29, 155, 240);
  font-weight: normal;
}
<p class="tweet">
  作为一名网页开发者,您希望使您的项目易于使用和导航。
</p>

<p class="tweet">
  在这里,<span class="twitter-handle">@chp_it</span> 概述了新开发者应具备的顶级技能。
</p>
英文:

Because you're styling everything in the &lt;p&gt; element, and the &lt;span&gt; is in the &lt;p&gt; element.

If you want a specific style for the &lt;span&gt;, you can give it style rules just like you do for the &lt;p&gt; element. For example, to reset the font-weight:

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

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

.tweet {
  width: 600px;
  line-height: 25px;
  font-weight: 800;
  margin-bottom: 20px;
  color: rgb(0, 0, 0);
}

.twitter-handle {
  color: rgb(29, 155, 240);
  font-weight: normal;
}

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

&lt;p class=&quot;tweet&quot;&gt;
  As a web developer, you&#39;ll want to make your projects easy to use and navigate around.
&lt;/p&gt;

&lt;p class=&quot;tweet&quot;&gt;
  Here &lt;span class=&quot;twitter-handle&quot;&gt;@chp_it&lt;/span&gt; outlines the top skills new developers should have.
&lt;/p&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年7月31日 21:46:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76804258.html
匿名

发表评论

匿名网友

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

确定