改变另一个div内的第一个div的颜色,两者之间有一个h2 [英] change color of first div within another div, with an h2 in between
本文介绍了改变另一个div内的第一个div的颜色,两者之间有一个h2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我注意到在下面的代码:
I notice that in the following code:
<div id="test1">
<div>1Lorem ipsum</div>
<div>2Lorem ipsum</div>
</div>
使用此css:
#test1 div:first-child{
color:red;
}
第一个div(1Lorem ...)我将html更改为:
The first div (1Lorem...) will be displayed red, but if I change the html to this:
<div id="test1">
<h2>Header</h2>
<div>Lorem ipsum</div>
<div>Lorem ipsum</div>
</div>
第一个div将不再显示红色。任何人都可以告诉我如何使第一个div(1Lorem ...)显示为红色,而保持h2?
The first div will no longer display red. Can anyone please advise me how to make that first div (1Lorem...) display in red while keeping the h2? I have to keep that h2 there, and I really need to use a method where this first-child div will be changed to red.
推荐答案
我们必须保留h2,而且我真的需要使用一个方法将这个first-child div改成红色。
#test1 div:first-child
只选择也第一个子
#test1 div:first-child
only selects a div that is also the first child
这篇关于改变另一个div内的第一个div的颜色,两者之间有一个h2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文