Select the li in the list - html

List:
<ul>
<li>
Item 1
<ul>
<li>
Item 1-1
<ul>
<li>Item 1-1-1</li>
<li>
Item 1-1-2
<ul>
<li><a href="#">Item 1-1-2-1</li>
</ul>
</li>
</ul>
</li>
<li>Item 1-2</li>
<li>Item 1-2</li>
</ul>
</li>
<li>Item 2</li>
</ul>
Here's some relevant CSS
#nav ul ul {
display: none;
}
#nav ul li:hover > ul {
display: block;
}
The first one will hide every drop down item. The second will match any ul that is a children of the parent #nav ul li:hover, if so display:block and the drop down is visible.
Now because when hovering a item, the items within will simply be listed below, this is not what I am looking to achieve. I want to move the Item 1-1-1 and Item 1-1-2 to be on the right of Item 1-1, the Item 1-1-1 needs to be on the right, Item 1-1-2 will be below it (acting as a drop-down list). I am not sure how I select that element.
Example: http://line25.com/wp-content/uploads/2012/css-menu/demo/index.html
Here's what I got so far:
http://jsfiddle.net/Gq8C2/
I tried with first-child, such as:
#nav ul li:hover > ul li:first-child {
display: block;
}
I also tried using position absolute and relative, It almost gave me the result I wanted, but I wasn't able to grab the first item...
There must be a better way of doing this...
How do I select it? And how do I make a similar behavior to that I've been describing above?

Why don't you just use the css/html of the page you linked to instead of trying to reinvent it?
HTML:
<nav>
<ul>
<li>Home</li>
<li>Tutorials
<ul>
<li>Photoshop</li>
<li>Illustrator</li>
<li>Web Design
<ul>
<li>HTML</li>
<li>CSS</li>
</ul>
</li>
</ul>
</li>
<li>Articles
<ul>
<li>Web Design</li>
<li>User Experience</li>
</ul>
</li>
<li>Inspiration</li>
</ul>
</nav>
CSS

Review this Fiddle http://jsfiddle.net/Gq8C2/10/
I use position:absolute for the sub-sub menu :
#nav ul li ul li ul {
position:absolute;
top:0;
left:100%;
}
In order to upgrade your code you can assign a class for each level of the menu like
<ul class="Third_level">

Related

Selecting last child of recursive list structure with CSS

I Want to select last Element of div.container <ul> inside last <li> with css.
The ul of nested will goes n level so please suggest to me if it possible with jquery also.
ul {
list-style: none;
margin: 0;
padding: 0;
}
<div class="container">
<ul>
<li>
<ul>
<li>Nested Item</li>
<li>
<ul>
<li>Nested Item</li>
<li>
<ul>
<li>Nested Item</li>
<li>
<ul>
<li>Nested Item</li>
<li>
<ul>
<li>Nested Item</li>
<li>Want to select list with css</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
view the image that i want to select with css
You can use some tricks to make it.
If you are looking for last element then you can use of :nth-last-child(n) selector, this matches on every element in the nth child and it doesn't look for type or its parent.
This is achieved as it counts from the last child.
.container ul li:nth-last-child(1)
{
color: red;
font-size:22px;
}
.container li li {
color: green;
font-size:12px;
}
Look at here:
MyFiddel

Struggling to get correct css formatting on nest ul list

I'm struggling with this, I'd like my first li to have a round bullet and then the nested li's to have an indented square bullet. My CSS trying to do this is below, default styling of my page is not putting any bullets in place.
Can someone help?
<ul>
<li>Simplification of a complex purchase category
<ul>
<li>Meet local regulatory compliance </li>
<li>Subitem 2</li>
</ul>
</li>
<li>Final list item</li>
</ul>
CSS
ul:first-child {
list-style-type:circle;
}
li:first-child {
list-style-type:square;
}
li:nth-child(2) {
list-style-type:square;
}
try this:
li {
list-style-type:circle;
}
li li {
list-style-type:square;
}
you could use classes on your tags to set the list-style-type.
HTML
<ul class="round">
<li>Simplification of a complex purchase category
<ul class="square">
<li>Meet local regulatory compliance </li>
<li>Subitem 2</li>
</ul>
</li>
<li>Final list item</li>
</ul>
CSS:
.round {
list-style-type:bullet;
}
.square {
list-style-type:square;
}
http://jsfiddle.net/8H9JA/

Getting the first anchor of first li inside the first ul only

I know how to get the first anchor of my li but the thing is, my code has 2 sub-menus of the same class and I want only the first ul to be affected.
<div id="navigation">
<ul>
<li>
Main menu
<ul class="sub-menu">
<li>Sub menu
<ul class="sub-menu">
<li>Sub sub menu</li>
<li>Sub sub menu</li>
<li>Sub sub menu</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
I can't find an anchor in your code, but I'm assuming that each <li> would contain one? In that case this is how you would select it:
#navigation > ul > li:first-child a{color:#FFF}
As it stands, the first-child isn't really needed - this would only come into play if you were to add more <li>s directly after the one you are aiming at.
JSFiddle
After your edit
You changed the code, so I guess I should update my answer. To target the 'main menu' anchor:
#navigation > ul > li > a{color:#F00}
JSFiddle
To target the first sub-menu anchor:
#navigation > ul > li > ul > li > a{color:#F00}
JSFiddle
If you dont want to use the :first-child you can use this:
Updated code and demo after the question was updated.
#navigation > ul > li > ul > li > a {color:red;}
This will only select the first <li><a> of the list, check the demo.
DEMO
Assuming you mean an anchor inside every li, something like that:
#navigation .sub-menu:first-child li:first-child a {
background-color: yellow;
}
<div id="navigation">
<ul class="sub-menu">
<li> <a href="#">1<a/>
</li>
<li> <a href="#">1.1<a/>
</li>
<ul class="sub-menu">
<li><a href="#">2<a/></li>
<li><a href="#">3<a/></li>
<li><a href="#">4<a/></li>
</ul>
</ul>
</div>
I intentionally added another li for the 1st ul - to make sure it works.
See JSFiddle example:
http://jsfiddle.net/rKynY/4/

Css dropdown menu pushes content down -fix for newbies?

I have looked though this site and found various answers, but none worked for me or I didn't know what to do exactly. Whenever I hover over the menu, the main content get pushed down & when I add "position:absolute" (I've tried some places^^), the whole menu gets deactivated or disappears enirely.
I have a blogger site and use a template from here: http://www.5202.de/2012/10/avantgardistisches-simple-wei-layout.html --> Download.
Please consider, when posting an answer, that I'm a total newbie in coding,and need very precise info;) I've made the menu with a generator, but I'm quite happy with it apart from that problem.
I really hope you can help and I think other newbies would benefit from an easy to understand/implement answer, too:)
Heres the css:
.PageList {text-align:center !important;}
.PageList li {display:inline !important; float:none !important;}
ul#main-nav {font-family:helvetica,arial,sans-serif;margin:0;padding:0;float:left;width:100%;font-size:0.9em;}
ul#main-nav li {margin:0;padding:0;list- style:none;float:left;margin:0;width:9em;position:relative;}
ul#main-nav li a {text- decoration:none;display:block;padding:0.6em;color:#0e0e0e;background:#cfcfcf;border- left:2px solid #fff;border-right:2px solid #fff;}
ul#main-nav li a:hover, ul#main-nav li a:focus {background:#ece1cf;border- left:2px solid gray;border-right:2px solid gray;}
ul#main-nav li ul {padding:0;margin:0;display:none;}
ul#main-nav li:hover ul {display:block;}
ul#main-nav li ul li {float:none;}
ul#main-nav li ul li a {font-size:0.9em;}]]>
Not sure about the Page list belonging, but anyways.
Now here's the html
<ul id="main-nav">
<li>Home</li>
<li>About
<ul>
<li>Me</li>
<li>This blog </li>
<li>Ressources</li>
<li>Legel stuff </li>
</ul>
</li>
<li>Photography
<ul>
<li>Projects</li>
<li>Equipment </li>
<li>Questions</li>
</ul>
</li>
<li>Scrappy Art
<ul>
<li>Scrapbooking </li>
<li>Art Journals </li>
<li>Mixed-Media </li>
<li>Crops & Co. </li>
</ul>
</li>
<li>DIY </li>
<li>Freebies
<ul>
<li>Free Stuff</li>
<li>Free Tutorials</li>
<li>Terms of Use </li>
</ul>
</li>
<li>Favorites
<ul>
<li>Blogging Friends </li>
<li>More Faves </li>
</ul>
</li>
<li>Features
<ul>
<li>Wonderland </li>
<li>Smashbook</li>
<li>Photo- Tips</li>
<li>Books</li>
<li>Lost Places </li>
</ul>
</li>
<li>Travel
<ul>
<li>La Gomera</li>
<li>London</li>
<li>Wroclaw</li>
</ul>
</li>
<li>Contact </li>
</ul>
How about you call the menu from another file (header) and set the background transparent make sure the body section overlaps the header when the drop down happens.
find ul#main-nav li ul {padding:0;margin:0;display:none;}
and change like this
ul#main-nav li ul {
padding:0;margin:0;
display:none;
position:absolute:/*Added*/
z-index:2;/*Added*/
}
You can change position of your child ul by giving position like top:10px;left:10px; etc
Working Demo Here

Creating dropdown navigation using only css

I have a ul list with nested ul elements. Currently it goes 3 levels deep. (main navigation, child, grandchild). I can't seem to get the dropdowns to work. Unforunately, I do not have the ability to place id's in the (ul) items. The best I could do i wrap the ul in a div with an ID on it. Any idea how I could do this? Here's the code I was working with, and I'm sorry if my css looks bad or makes no sense. I'm a novice at this.
Code
http://jsfiddle.net/grem28/ZhNDZ/1/ (jsfiddle for CSS)
<div id="nav">
<ul>
<li id="but_products" >Products
<ul>
<li id="but_boilers" >Boilers</li>
</ul>
</li>
<li id="but_resources" >Resources
<ul>
<li id="but_engineeringLibrary" >Engineering Library
<ul>
<li id="but_detroit" >Detroit Radiant MEA numbers</li>
</ul>
</li>
</ul>
</li>
<li id="but_contactUs" >Contact Us</li>
</ul>
</div>
damien
Here's an example of a functioning 3-tier CSS drop-down navigation system:
HTML
<nav>
<ul>
<li>
Menu One
<ul>
<li>
Menu One Item One
<ul>
<li>Menu One Item One Submenu Item One</li>
<li>Menu One Item One Submenu Item Two</li>
<li>Menu One Item One Submenu Item Three</li>
<li>Menu One Item One Submenu Item Four</li>
</ul>
</li>
<li>
Menu One Item Two
<ul>
<li>Menu One Item Two Submenu Item One</li>
<li>Menu One Item Two Submenu Item Two</li>
<li>Menu One Item Two Submenu Item Three</li>
<li>Menu One Item Two Submenu Item Four</li>
</ul>
</li>
<li>
Menu One Item Three
<ul>
<li>Menu One Item Three Submenu Item One</li>
<li>Menu One Item Three Submenu Item Two</li>
<li>Menu One Item Three Submenu Item Three</li>
<li>Menu One Item Three Submenu Item Four</li>
</ul>
</li>
<li>
Menu One Item Four
<ul>
<li>Menu One Item Four Submenu Item One</li>
<li>Menu One Item Four Submenu Item Two</li>
<li>Menu One Item Four Submenu Item Three</li>
<li>Menu One Item Four Submenu Item Four</li>
</ul>
</li>
</ul>
</li>
<li>
Menu Two
<ul>
<li>Menu Two Item One</li>
<li>Menu Two Item Two</li>
<li>Menu Two Item Three</li>
<li>Menu Two Item Four</li>
</ul>
</li>
</ul>
</nav>
CSS
body { font-family: Helvetica, Arial, Sans-serif; line-height: 1.5em; }
a:hover { color: #cc0000; }
/* Hide submenu */
nav ul > li > ul,
nav ul > li > ul > li > ul { display:none; }
/* Layout menubar and menus */
nav { background:#ddd; padding:0.25em 0.5em; }
nav > ul > li { cursor: pointer; display:inline-block; padding:0 1em; }
nav > ul > li > ul { background: #ddd; padding:0.5em; position: absolute; z-index: 1000; }
nav > ul > li > ul > li > ul { background: #ccc; padding:0.5em; position: absolute; left: 90%; top: 0; z-index: 1001; }
/* show submenu on hover */
nav ul > li:hover > ul,
nav ul > li > ul > li:hover > ul { display:block; width:10em; }
Fiddle: http://jsfiddle.net/kboucher/nrAPu/
Hope this helps.