html - CSS get second element by className without JS -


i want headings title titanic 20px high. can accomplish applying css-rule:

h1[title="titanic"] {font-size:20px;} 

now want second heading class red. if every heading had same parent (thus in same div), done this:

h1[title="titanic"]:nth-of-child {color:red;} 

however, when headings not in same parent, don't know how select second heading. want know css-rule need color second heading red in following example:

<h1 title="titanic">heading one</h1> <span><h1 title="titanic">heading two</h1></span> 

css doesn't have way select nth element document-wide. have rely on structure determine whether or not select second h1.

for example, can choose when first h1 comes before span present, (ignoring appropriateness of having h1 within span in example...):

h1[title="titanic"] + span > h1[title="titanic"] 

or if have set of these, see if top-level h1 elements , span elements share same parent. if do, can use span:nth-child(2) ensure don't match of other spans:

h1[title="titanic"] + span:nth-child(2) > h1[title="titanic"] 

if can't make any assumptions document structure @ all, you're out of luck.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -