CSS如何选择第一个出现的元素后另一个元素 [英] CSS how to select first occurring element after another element

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

问题描述

我在网页上获得以下HTML代码

 < h4>一些文字< / h4> 
< p>
更多文字!
< / p>

在我的CSS中,我有以下选择器来设计H4元素。上面的HTML代码仅仅是整个代码的一小部分,有几个div更多的是属于一个shadowbox

 # sb-wrapper#sb-wrapper-inner#sb-body #myDiv h4 
{
color:#614E43;
margin-top:5px;
margin-left:6px;

$ / code>

所以我对我的H4元素有正确的样式,但我也想在我的HTML中设置段落标记的样式。这可能与CSS选择器?如果是的话,我该怎么做?

h4 + 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 paragraph 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.

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

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