Select first occurring element after another element(在另一个元素之后选择第一个出现的元素)
问题描述
我在一个页面上有以下 HTML 代码:
<h4>一些文字</h4><p>还有一些文字!</p>
在我的 .css
中,我有以下选择器来设置 h4
元素的样式.上面的 HTML 代码只是整个代码的一小部分;有几个 div
更多地包裹在属于 shadowbox 的周围:
#sb-wrapper #sb-wrapper-inner #sb-body #myDiv h4{颜色:#614E43;边距顶部:5px;左边距:6px;}
所以,我的 h4
元素具有正确的样式,但我还想在我的 HTML 中设置 p
标记的样式.
这可以通过 CSS 选择器实现吗?如果是,我该怎么做?
#many .more.selectors h4 + p { ... }
这称为相邻兄弟选择器.p>
I've got the following HTML code on a page:
<h4>Some text</h4>
<p>
Some more text!
</p>
In my .css
I've got the following selector to style the h4
element. The HTML code above is just a small part of the entire code; there are several div
s more wrapped around belonging to a shadowbox:
#sb-wrapper #sb-wrapper-inner #sb-body #myDiv h4
{
color : #614E43;
margin-top : 5px;
margin-left : 6px;
}
So, I have the correct style for my h4
element, but I also want to style the p
tag in my HTML.
Is this possible with CSS-selectors? And if yes, how can I do this?
#many .more.selectors h4 + p { ... }
This is called the adjacent sibling selector.
这篇关于在另一个元素之后选择第一个出现的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!