什么CSS选择器可以用来选择第一个div在另一个div [英] What CSS selector can be used to select the first div within another div
本文介绍了什么CSS选择器可以用来选择第一个div在另一个div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有类似的:
<div id="content>
<h1>Welcome to Motor City Deli!</h1>
<div style=" font-size: 1.2em; font-weight: bolder;">Sep 19, 2010</div>
<div > ... </div>
第二个div(contentdiv中的第一个div)的css选择器是什么,这样我可以在div中设置日期的字体颜色?
What is the css selector for the second div (1st div within the "content" div) such that I can set the font color of the date within that div?
推荐答案
您的问题的最正确答案是...
The MOST CORRECT answer to your question is...
#content > div:first-of-type { /* css */ }
$ b b
这会将CSS应用于第一个div,它是#content的直接子元素(可能是也可能不是#content的第一个子元素)
This will apply the CSS to the first div that is a direct child of #content (which may or may not be the first child element of #content)
另一个选项:
#content > div:nth-of-type(1) { /* css */ }
这篇关于什么CSS选择器可以用来选择第一个div在另一个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文