在另一个元素之后选择第一个出现的元素 [英] Select first occurring element after another element

查看:15
本文介绍了在另一个元素之后选择第一个出现的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个页面上有以下 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 divs 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.

这篇关于在另一个元素之后选择第一个出现的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆