I have this structure
<nav>
<ul id="nav" class="sf-menu sf-navbar sf-js-enabled sf-shadow">
<li id="level1-home" class="current sfHover sf-breadcrumb">
<a href="/Admin/Home/Index">
...
And I’d like to style the <a> tags without affecting any other links in the site. What’s the best way to do this?
Targeting by ID
In your provided code you have an
idof “nav” on yourulelement. This can be used to specify the container of the anchors you’d like to target:This will affect all
aelements within (regardless of nested depth) an element that has theidof “nav”.Targeting by Unique Path
Examine the parents of your links for uniqueness. Links that fall within a
navelement, within aheaderelement can be styles like this:Links that fall within a
navcontained within afootercould be addressed like this:Disclaimer
The
header,footer, andnavtags are all HTML5 constructs. To broad support across older browsers, be sure to include the HTML5Shiv when working with these tags.