/    Sign up×
Community /Pin to ProfileBookmark

Syntax question

I have found this as part of a navigation script.

[code=php]
ul.nav,
.nav ul { …. margin & list-style-type setting … }

ul.nav { … width setting … }

ul.nav>li { … margin & padding setting … }

ul.nav li>ul { … sub-list item settings of width, margin, left, display …}

ul.nav li:hover>ul { … display change … }

nav ul li a { … display changes without hover …}

ul.nav,
.nav ul,
nav ul li a { … color settings only … }

ul.nav li:hover { … color settings only … }

ul { border settings … }

.nav a { … text decoration … }

[/code]

My question is how does the syntax differ in results?
For example
ul.nav,
.nav ul {
looks like both control the same thing (?)
All <UL> with a ‘class=nav”
and
All ‘class=nav’ with <UL> tags are given a paritcular look when rendered.

Is there a purpose for the “duplicated” syntax, or is this just good practice?

Later into the style there is a:
ul.nav>li {
and
ul.nav li>ul {

What does the ‘>’ do in this context and is is different from:
ul.nav li {
and
ul.nav li ul {

The style sheet works well but I just don’t understand the syntax differences
and my references do not dwell on this.

Thanks for any insight. ?

to post a comment
CSS

2 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Jun 18.2008 — "ul.nav" gets all uls with the class "nav".

".nav ul" gets all uls who are a descendant of an element with the class "nav".

I'd say that is a multilevel navigation, and the second is to control the inner uls.

">" is the direct child selector (" " or space is the child selector) and selects all elements who are a direct descendant of the previous element. It only works in IE 7+.

So:

"ul.nav>li" selects lis whose parent is a ul with the class nav.

"ul.nav li>ul" selects all uls whose parent is a li, which is a descendant of a ul with the class nav.
[code=html]
<ul class="nav"> <!-- ul 1-->
<li>1 <!-- li 1-->
<ul class="nav"> <!-- ul 2 -->
<li>1.1</li> <!-- li1.1 -->
<li>1.2</li> <!-- li 1.2-->
</ul>
</li>
<li> <!-- li 2 -->
<div> <!-- div1 -->
<ul> <!-- ul 3 -->
<li></li> <!-- li 2.1 -->
</ul>
</div>
</li>
</ul>
[/code]

ul.nav gets ul1 and ul2.

.nav ul gets ul2 and ul3.

ul.nav>li gets li1 and li2

ul.nav li gets all the lis (li1,li1.1,li1.2,li2,li2.1).

ul.nav li>ul gets ul2 (note NOT ul3 because that is not a direct descendant of an li, its parent is a div.
Copy linkTweet thisAlerts:
@JMRKERauthorJun 18.2008 — Thank you ? ... I think I need to study on this before I ask anymore questions.
×

Success!

Help @JMRKER spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...