html - 在css中设置多个段落样式

标签 html css

这是一个顶级问题,更多的是基于我对 css 的无知。我正在尝试在 css 中创建两种段落样式,一种字体大小为 20px,另一种字体大小为 14px。但是,无论我做什么,字体都是一样的。附件是我现在正在做的事情的一个例子,如果有人能指出我的解决方案,我将不胜感激。为了简洁起见,我省略了不必要的代码。

html代码是这样的

<p>This is the html section with 20 px font</p>

<p class="new_font"> This is the html section with 8px font</p>
/* I have also tried this with a <div class="new_font"> and and <p id="new_font>"*/

css代码是这样的

p {
     /*text-indent: 1.5em;*/
     font: 20px Helvetica, Sans-Serif;
     color: white;
     overflow: hidden;
     padding: 15px;
     text-align: justify;
     background: rgb(0, 0, 0,0.3); /* fallback color */
     background: rgba(0, 0, 0, 0.7);
}
p new_font {
     /*text-indent: 1.5em;*/
     font: 14px Helvetica, Sans-Serif;
     color: white;
     overflow: hidden;
     padding: 15px;
     text-align: justify;
     background: rgb(0, 0, 0,0.3); /* fallback color */
     background: rgba(0, 0, 0, 0.7);
} 

最佳答案

您的 CSS 无效,这就是它不适用的原因:

p new_font {
   /* ... */
}

应该写成

p.new_font {
   /* ... */
}

p new_font 用英语读作“选择位于 p 标签内的所有 new_font 标签”。

p.new_font 用英文读作“选择所有 p 标签,其 class 属性设置为 new_font

关于html - 在css中设置多个段落样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33763839/

相关文章:

javascript - 在文本消息中从底部滚动到顶部,例如使用 React 模态

html - 表格单元格中的段落未随屏幕大小调整大小

javascript - 实时追踪路线 Maps api V3

javascript - 当输入字段为空时如何禁用按钮?

javascript - 带 Bootstrap 的图片库,图片更大

css - 支持现代和旧浏览器的 CSS 2 与 CSS 3

javascript - Ajax XML 每 10 秒更新一次

css - html5 按钮背景图像状态

html - 您可以在 Zurb Foundation 4 上设置中柱吗?

javascript - 我的大学 html 联系表需要帮助