sample 1 sample 2 All geek questions in one placeHow to target the first link inside a div using CSS?For example, I have this:<div> <a href="#">sample 1</a> <a href="#">sample 2</a> <a href="#">sample 3</a> </div> I want to target the first link using CSS.+4css pseudo-class targetingDanny cooper Nov 08 '12 at 8:45source share3 answersYou can use the first-child selector: div > a:first-child { /* your css */ } +10sticksu Nov 08 '12 at 8:47source shareTry this code: div > a:first-child{ //your css code } +8Alessandro minoccheri Nov 08 '12 at 8:47source share div a:nth-of-type(n) { /* css */ } where n is the number of the desired line. in your case div a:nth-of-type(1) { /* css */ } +2Nick ginanto Nov 08 '12 at 8:50source shareSource: https://habr.com/ru/post/1444752/More articles:CCM-AES from the Linux kernel - cThe "ng-click" attribute is not allowed for an element in netbeans - angularjsHow to request the use of Elastica - phpMove any RelativeLayout with your finger (without changing layout settings) - androidXML serialization of a non-nested repeating sequence - c #Rails 3.2 bootstrap-sass does not install - ruby-on-railsWhat should be the result? - cjavascript window.open not working in IE - javascriptreading / writing google spreadsheet content using javascript - javascriptNHibernate Failed to Synchronize Database State with Session - c #All Articles
For example, I have this:
<div> <a href="#">sample 1</a> <a href="#">sample 2</a> <a href="#">sample 3</a> </div>
I want to target the first link using CSS.
You can use the first-child selector:
div > a:first-child { /* your css */ }
Try this code:
div > a:first-child{ //your css code }
div a:nth-of-type(n) { /* css */ }
where n is the number of the desired line. in your case
div a:nth-of-type(1) { /* css */ }
Source: https://habr.com/ru/post/1444752/More articles:CCM-AES from the Linux kernel - cThe "ng-click" attribute is not allowed for an element in netbeans - angularjsHow to request the use of Elastica - phpMove any RelativeLayout with your finger (without changing layout settings) - androidXML serialization of a non-nested repeating sequence - c #Rails 3.2 bootstrap-sass does not install - ruby-on-railsWhat should be the result? - cjavascript window.open not working in IE - javascriptreading / writing google spreadsheet content using javascript - javascriptNHibernate Failed to Synchronize Database State with Session - c #All Articles