开发者

access html content through CSS?

开发者 https://www.devze.com 2022-12-20 05:53 出处:网络
<div id=menu> <ul> <li class=\"section-title\">auto-text1</li> <li class=\"section-title\">auto-text2</li>
<div id=menu>
 <ul>
  <li class="section-title">auto-text1</li>
  <li class="section-title">auto-text2</li>
  <li class="section-title">auto-text3</li>
 </ul>开发者_StackOverflow社区
</div>

How can I give special treatment to auto-text3 through css?


See section 6.6.5.7. of the CSS3 - future - proposal:

:last-child pseudo-class

Same as :nth-last-child(1). The :last-child pseudo-class represents an element that is the last child of some other element.

ul > li:last-child { }

http://www.w3.org/TR/css3-selectors/#last-child-pseudo

(In your example </menu> probably is meant to be the closing </div>.)

For the time being I guess it's still best to use classes marking the first and last list element, or simple Javascript on your #menu id.


You could use the :nth-of-type() pseudo-class selector:

#menu > ul > li.section-title:nth-of-type(3)

This will select the third element of all li elements with the class section-title.


Just to clarify the other answers, there aren’t (currently) any CSS selectors that let you select an element based on its content.

0

精彩评论

暂无评论...
验证码 换一张
取 消