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.
Related
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
This question already has answers here:
css how to only make bold fonts for first <ul> set
(4 answers)
Closed 6 years ago.
How to set bold style with CSS only to the "titles" in this code?
Live example: jsbin.com/xofudovoda/
.container > ol {
font-weight: bold;
}
<div class="container">
<ol type="I">
<li>
Title 1
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
<li>
Title 2
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
</ol>
</div>
You can set bold on first level <ol>, and reset it on the second level <ol>s.
.container ol {
font-weight: bold;
}
.container ol ol {
font-weight: normal;
}
<div class="container">
<ol type="I">
<li>
Title 1
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
<li>
Title 2
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
</ol>
</div>
ol li { font-weight: 700 }
ol li ol li {font-weight: 300 }
You can use the following CSS:
.container ol li {
font-weight: bold;
}
.container ol li ol li{
font-weight: normal;
}
li
{
font-weight:normal;
}
.container > ol>li {
font-weight: bold;
}
Add a rule for li. That forces the child <li> elements to use their own style instead of inheriting it from their parent.
Set all the li to font-weight normal, then only apply the bolding to direct children of the original ol.
li {
font-weight: normal;
}
.container > ol:first-child > li {
font-weight: bold;
}
<div class="container">
<ol type="I">
<li>
Title 1
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
<li>
Title 2
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
</ol>
</div>
Take the Title in span tag and than to that span apply font-weight:bold ol >li > span {font-weight:bold;}
working example : http://jsbin.com/gifaliluve/edit?html,css,output
Here is the code :
<html>
<body>
<head>
<style>
ol >li > span {font-weight:bold;}
</style>
</head>
<div class="container">
<ol type="I">
<li>
<span>Title 1</span>
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
<li>
<span>Title 1</span>
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
</ol>
</div>
</body>
</html>
Nth-child will make bold first sub items of each,
ol> li> ol>li:nth-child(odd){
font-weight:bold;
}
Edit 1:
Sorry I understood wrong, this may help.
ol>li {
font-weight:bold;
}
ol > li > ol > li {
font-weight:normal;
}
Hope helps,
Problem is that you've got ordered lists nested within the li's you're trying to target specifically. Try the following:
.container > ol > li {
font-weight: bold;
}
.container > ol > li ol {
font-weight: normal;
}
<div class="container">
<ol type="I">
<li>
Title 1
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
<li>
Title 2
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
</ol>
</div>
Or, another way:
.container li {
font-weight: bold;
}
.container > ol > li > ol > li {
font-weight: normal;
}
<div class="container">
<ol type="I">
<li>
Title 1
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
<li>
Title 2
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
</ol>
</div>
I'm trying to style two unordered lists differently on my page - no list style for the nav at the top, and regular list styling in the form.
Here's my simplified markup:
<html>
<head>
<style>
nav
{
background-color:lightgrey;
}
nav ul, li
{
list-style:none;
display:inline-block;
}
form ul, li
{
color:red;
}
</style>
</head>
<body>
<nav>
<ul>
<li>Nav Item 1</li>
<li>Nav Item 2</li>
<li>Nav Item 3</li>
</ul>
</nav>
<form>
<ul>
<li>Form Item 1</li>
<li>Form Item 2</li>
<li>Form Item 3</li>
</ul>
</form>
</body>
When this is run, both the nav and form ULs are coloured red and also lack list styling.
Replace nav ul, li with nav ul, nav li and form ul, li with form ul, form li.
Your code should be as follows:
<html>
<head>
<style>
nav
{
background-color:lightgrey;
}
nav ul, li
{
list-style:none;
display:inline-block;
}
/*Targets all "li" elements that have "form" as parent*/
form ul, form ul li
{
color:red;
}
</style>
</head>
<body>
<nav>
<ul>
<li>Nav Item 1</li>
<li>Nav Item 2</li>
<li>Nav Item 3</li>
</ul>
</nav>
<form>
<ul>
<li>Form Item 1</li>
<li>Form Item 2</li>
<li>Form Item 3</li>
</ul>
</form>
</body>
I am trying to make a menu with submenus. I wrote my HTML and it looks like:
<nav>
<ul>
<li>Home</li>
<li>Page 1
<ul>
<li>dropdown 1</li>
<li>dropdown 2</li>
<li>submenu
<ul>
<li>submenu 1</li>
<li>submenu 2</li>
<li>submenu 3</li>
</ul>
</li>
</ul>
</li>
<li>Page 2</li>
<li>Page 3</li>
</ul>
</nav>
I have a stylesheet linked to it, and it looks like:
nav ul {
display:inline-block;
position:relative;
list-style:none;
}
nav ul ul {
display:none;
}
nav ul li:hover > ul {
display:block;
}
For some reason the list is displayed as a block. I tried float:left, and it made no difference.
You have to to put display:inline-block for li elements:
nav li {
display:inline-block;
}
check here the example: http://jsfiddle.net/9y1uzqye/1/
You need to make the individual list items use block display, not the list itself.
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">