什么 CSS 选择器可以用来选择另一个 div 中的第一个 div
- 作者: 用户50791008
- 来源: 51数据库
- 2022-10-20
问题描述
我有类似的东西:
<div id="content><h1>欢迎来到汽车城熟食店!</h1><div style="font-size: 1.2em; font-weight: bolder;">2010 年 9 月 19 日</div>... </div>第二个 div(内容"div 中的第一个 div)的 css 选择器是什么,以便我可以在该 div 中设置日期的字体颜色?
解决方案您的问题最正确的答案是......
#content >div:first-of-type {/* css */}这会将 CSS 应用于作为 #content 的直接子元素的第一个 div(它可能是也可能不是 #content 的第一个子元素)
另一种选择:
#content >div:nth-of-type(1) {/* css */}I have something like:
<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>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 */ }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)
Another option:
#content > div:nth-of-type(1) { /* css */ }
推荐阅读
热点文章
检查拆分键盘
0
带有“上一个"的工具栏和“下一个"用于键盘输入AccessoryView
0
Activity 启动时显示软键盘
0
UIWebView 键盘 - 摆脱“上一个/下一个/完成"酒吧
0
在 iOS7 中边缘滑动时,使键盘与 UIView 同步动画
0
我的 iOS 应用程序中的键盘在 iPhone 6 上太高了.如何在 XCode 中调整键盘的分辨率?
0
android:inputType="textEmailAddress";- '@' 键和 '.com' 键?
0
禁用 iPhone 中键盘的方向
0
Android 2.3 模拟器上的印地语键盘问题
0
keyDown 没有被调用
0