css - 如何仅使用类选择器更改段落内特定文本的颜色?

标签 css xhtml strict

我正在学习一些 CSS,我遇到的其中一个问题就是这个。

我看到了这个 html,我应该编写 CSS 来强调(红色代表辣味,绿色代表素食)强标签的素食和辣味菜单项及其描述符(强标签中的“素食主义者”和“辣!!!”)。通过编写包含在 html 下方的 css,我对描述符有了一些运气,但我似乎无法找到允许我将它们分开的选择器组合。在不包括非素食/非辛辣选项的情况下,我还没有在菜单项的标题上取得任何成功。我应该提一下,一切都必须用 CSS 2.0 来完成。如果有人有一些见识,我将不胜感激!

开胃菜

  <p>
     <strong>Mozzarella Sticks</strong><br />
     Golden fried and served with marinara sauce. - $7.49<br />
  </p>

  <p>
     <strong>Spicy Buffalo Wings</strong><br />
     An American classic with a kick! Grilled to perfection
     and tossed in the hottest sauce we got! - $8.99<br />
     <strong>Spicy!!!</strong>
  </p>

  <p>
     <strong>Crab Wontons</strong><br />
     Crab, cream cheese, scallions, bell peppers. - $6.99
  </p>

  <p>
     <strong>Vegetable Spring Rolls</strong><br />
     Cabbage, ginger, carrots, celery, scallions, onions,
     black mushrooms, glass noodles, rolled in a crispy
     wrapper. - $6.99<br />
     <strong>Vegetarian</strong>
  </p>

  <p>
     <strong>Nachos</strong><br />
     Creamy white queso blended with fresh tomatoes,
     red onion, cilantro and roasted poblanos. Served
     with warm tortilla chips. - $6.99
  </p>

  <p>
     <strong>Edamame</strong><br />
     Salted soybeans in the pod. - $5.99<br />
     <strong>Vegetarian</strong>
  </p>

到目前为止,这是我的 CSS

    div#appetizers br + strong
{
color:red;
}

最佳答案

使用 :nth-of-type()表示哪个的方法<p>您要定位的元素。 但是你只能用css2……没关系。使用像这个例子的 css2 版本:

在 CSS3 中:ol > li:nth-child(3) == css2:ol > li:first-child + li + li

试试你的 <p> (假设您知道您提供的 html 的包含元素) 比如 #somedivID > p:first-child + p strong {color:red;}

关于css - 如何仅使用类选择器更改段落内特定文本的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25920910/

相关文章:

javascript - 使用jquery和php的评论回复程序?

perl - 如何将 `our` 类变量与 `UNITCHECK` 正确地与 `use strict` 一起使用?

css - flex 盒子。元素未在同一高度对齐

css - 如何在 ng-option 中为每个选项应用 font-family

eclipse - 如何通过 Eclipse IDE 在 XHTML 中使用 Facelets 开发应用程序?

java - Type=带有特殊字符的文本模式问题

javascript - JavaScript的严格模式是如何实现的

Perl,可变行为,基于名称的差异

javascript - 制作一个div全宽和全高

css - JSP 中的内联 CSS 样式