我正在学习一些 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/