:第一个孩子选择器或equivelant(:first

编程入门 行业动态 更新时间:2024-10-27 10:34:07
第一个孩子选择器或equivelant(:first-child selector or equivelant)

我想设置UL的第一个列表项的样式,列表项包含在<a>标记中。

我本来以为它会很简单,就是这样: http : //jsfiddle.net/PHhFX/但这不起作用。

有人知道吗?

I want to style the first list item of a UL, the list item is encased in an <a> tag.

I would have thought it would be simple, just this: http://jsfiddle.net/PHhFX/ but that isn't working.

Anyone any clue?

最满意答案

您不应该在<a>包含<li> - 在您的HTML中,您只能将<li>元素作为<ul>子元素。

你可能想要反过来做这件事( <li> <a> ),然后选择

ul li:first-child

jsFiddle预览

You're not supposed to encase a <li> in an <a> — in your HTML you can only have your <li> elements as children of the <ul>.

You probably meant to do it the other way around (<a> within <li>), then select

ul li:first-child

jsFiddle preview

更多推荐

本文发布于:2023-07-22 12:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219993.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第一个   孩子   选择器   equivelant

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!