This CSS tutorial explains how to use the CSS selector called :first-child with syntax and examples. The CSS :first-child selector allows you to target an element that is the first child element within its parent.
body *:first-child {font-weight: bold;} p:first-child {font-size: 125%;} Summary CSS Version 2 CSS Syntax :first-child { style properties } Browser compatibility:first-child Yes 7.0 Yes Yes Yes Example An example showing how to use :first-child CSS selector. ...
:first-child选择器是 CSS 中的一个伪类,用于选取匹配某种选择器的元素中的第一个子元素。如果某个元素是父元素的第一个子元素,则该元素会被选中。 语法 :first-child选择器的语法如下: selector:first-child { /* styles */ } 其中,selector为任意合法的 CSS 选择器,如div、.class、#id等。
This pseudo-class matches an element only if it’s the first child element of its parent element.
$("p:first-child").css("background-color","yellow"); });</script></head><body><p>The first paragraph in body.</p>*选取该元素<divstyle="border:1px solid;"><p>The first paragraph in div.</p>*选取该元素<p>The last paragraph in div.</p></div><br><divstyle="border:1px sol...
How to use a not first child selector in CSS - There are various selectors in CSS out of all those selectors, so use :not(:first-child) selector. We can very easily achieve this using the :not and :first-child selectors in a combination. For example, if
Here the :first-child pseudo class style applies to allpdirect child elements of div of class foo. To apply style to all direct child and descendant p elements we could have used.foo p:first-child. See more info atCSS direct child vs any descendant selector. ...
Selects $('li:first-child') all <li> elements that are the first child of their parent element $(.myclass:first-child') all elements with the class myclass that are the first child of their parent element <html> <head> <script src="http://java2s.com/style/jquery-1.8.0.min.js"...
ul li:first-child { color: red; } The above CSS rule will apply thecolor: red;property only to the first list item, because it is the first child of its parentulelement. Compatibility The:first-childselector is supported by all major web browsers, including Internet Explorer 9 and later...
CSS伪类:first-child CSS 伪类用于向某些选择器添加特殊的效果。 CSS伪类的基础语法: selector : pseudo-class{property:value} 当然,CSS类也可以与伪类搭配使用: selector.class : pseudo-class{property:value} 在我第一次看到:first-child伪类时,我的第一个感觉就是,这是在针对指定元素的第一个子元素起作用...