Make dropdown child 100% of container - html

I have a dropdown inside a black container of 600px and i would like to have the red childrens show in a width of 100% of container instead of 100% of page width as it happens now. I need this to be in % because the website is responsive.
Please take a look at Jsfiddle Demo
<div id="navcontainer">
<ul>
<li style="display: inline;float: left;">
Filters
<ul style="text-align:left">
<li>Brand</li>
<li>Model</li>
<li>Color</li>
<li>Features</li>
</ul>
</li>
<li style="display: inline;float: right;">
Sort by
<ul style="text-align:right">
<li>Newest</li>
<li>Oldest</li>
<li>Cheapest</li>
</ul>
</li>
</ul>
</div>

add position:relative; for - #navcontainer ul
#navcontainer {
background:#222;
margin: 0 auto;
width: 600px;
}
#navcontainer ul {
text-align:center;
margin:0;
padding:0;
list-style:none;
width:100%;
position:relative;
}
#navcontainer ul li {
display:inline;
/*position:relative;*/
}
#navcontainer ul li a {
display:inline-block;
color:#fff;
font-size:20px;
padding:20px 30px;
}
#navcontainer ul li a:hover {
background:#999;
}
#navcontainer ul ul {
position:absolute;
left:0;
top:100%;
z-index:10;
width:100%;
display:none;
background:red;
}
#navcontainer ul ul li {
float:none;
}
#navcontainer ul ul li a {
text-align:left;
}
#navcontainer ul li:hover ul {
display:block;
}
<div id="navcontainer">
<ul>
<li>
Eggs
<ul>
<li>sub menu</li>
<li>sub menu</li>
<li>sub menu</li>
<li>sub menu</li>
</ul>
</li>
</ul>
</div>

you can use position attribute for many diffrent uses but there you need to hava a contained sub menu and you cant use position:absolute; for parent element
you can use it for child elements and here you do it for both of theme .
change this line to solve your problem .
#navcontainer ul ul {
position:relative;
}
sorry for my bad language skils .

The above description and view the demo you away into a problem solved
You should add the parent element the following characteristics :
#navcontainer {
background: rgb(34, 34, 34) none repeat scroll 0 0;
border: 1px solid;
height: 65px;
margin: 0 auto;
position: relative;
text-align: center;
width: 600px;
}

Related

How do I make menu retain hover state when submenu is active?

What do I need to include in my CSS to get my menu text to stay black when hovering over a submenu?
I've tried systematically going through my current :hover elements, including > when ever possible, and adapting the relevant parts from other codes into the CSS. I've also combed through similar questions in hopes to find applicable code but have not been successful.
#menu {
width: 100%;
position: fixed;
background: #333;
color: #fff;
}
#menu ul.left {
position:relative;
float:left;
margin:0;
padding:0px;
}
#menu ul a {
display:block;
color:#fff;
text-decoration:none;
padding:0 15px;
}
#menu ul a:hover {
display:block;
color: #333;
text-decoration:none;
padding:0 15px;
}
#menu ul li {
list-style-type: none;
position:relative;
float:left;
margin:0;
padding:0px;
}
#menu ul li:hover {
background:#f6f6f6;
color:#333;
}
#menu ul ul {
display:none;
position:absolute;
background: #f6f6f6;
color: #333;
}
#menu ul li:hover > ul {
display:block;
}
<nav id="menu">
<ul class="left">
<li>Home</li>
<li>Menu 1
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</li>
<li>Sub Menu 4
</ul>
</li>
</ul>
</nav>
Expected results: hovering from Menu 1 to Sub Menu x will keep the #333 colored text on Menu 1.
Actual results: hovering from Menu 1 to Sub Menu x will revert to #f6f6f6 colored text on Menu 1.
Added a element to the #menu ul li:hover in css.
#menu {
width: 100%;
position: fixed;
background: #333;
color: #fff;
}
#menu ul.left {
position:relative;
float:left;
margin:0;
padding:0px;
}
#menu ul a {
display:block;
color:#fff;
text-decoration:none;
padding:0 15px;
}
#menu ul a:hover {
display:block;
color: #333;
text-decoration:none;
padding:0 15px;
}
#menu ul li {
list-style-type: none;
position:relative;
float:left;
margin:0;
padding:0px;
}
#menu ul li:hover a{
background:#f6f6f6;
color:#333;
}
#menu ul ul {
display:none;
position:absolute;
background: #f6f6f6;
color: #333;
}
#menu ul li:hover > ul {
display:block;
}
<nav id="menu">
<ul class="left">
<li>Home</li>
<li>Menu 1
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</li>
<li>Sub Menu 4
</ul>
</li>
</ul>
</nav>

Add a vertical Sub menu using css and html

I have a menu drop down list which is done using css and html. Now, I want to have an extension of sub menu on the existing sub menu, when I hover the "Audit Report for example, it should show another sub menu vertically. How can I achieve that? This is my existing codes in css and html.
css
.menuPanel
{
width: auto;
height: 32px;
top: 5px;
border-bottom: 1px solid #808080;
background-color: #4f4545;
}
.nav,.nav ul
{
list-style: none;
margin:0;
padding:0;
}
.nav {
position:relative;
left: 2px;
height: auto;
}
.nav ul
{
height:0;
left:0;
overflow: hidden;
position:absolute;
}
.nav li
{
float:left;
position:relative;
}
.nav li a
{
-moz-transition:1.0s;
-o-transition:1.0s;
-webkit-transition:1.0s;
transition:1.0s;
background-color: #4f4545;
display: block;
color:#FFF;
text-decoration:none;
font-size:12px;
line-height:32px;
padding:0px 30px;
}
.nav li:hover > a
{
background: #8CCA33;
border-color: #6E67A6;
color:#fff;
}
.nav li:hover ul.subs
{
height:auto;
width: 250px;
z-index: 10;
}
.nav ul li
{
-moz-transition:0.3s;
-o-transition:0.3s;
-webkit-transition:0.3s;
opacity:0;
transition:0.3s;
width:100%;
}
.nav li:hover ul li
{
opacity:1;
-moz-transition-delay:0.2s;
-o-transition-delay:0.2s;
-webkit-transition-delay:0.2s;
transition-delay:0.2s;
}
.nav ul li a
{
background: #4f4545;
border: 1px solid #808080;
color:#fff;
line-height:1px;
-moz-transition:1.5s;
-o-transition:1.5s;
-webkit-transition:1.5s;
transition:1.5s;
}
.nav li:hover ul li a
{
line-height:32px;
}
.nav ul li a:hover
{
background:#8CCA33;
}
aspx page design
<ul class="nav">
<li>HOME</li>
<li>FILE &#9662
<ul class="subs">
<li>Tenants List</li>
<li>Users List</li>
<li>Tenant Rental</li>
</ul>
</li>
<li>REPORTS &#9662
<ul class="subs">
<li>Audit Reports
<ul>
<li><a href='#'>Sub Product</a></li>
<li><a href='#'>Sub Product</a></li>
</ul>
</li>
<li>Leasing Reports</li>
<li>Marketing Reports</li>
</ul>
</li>
<li id="admin" visible="true" runat="server">ADMIN &#9662
<ul class="subs">
<li>System Logs</li>
<li>User Request</li>
</ul>
</li>
<li>LOG-OUT
</li>
</ul>
</div>
You have to do a new CSS-Style for .nav .subs ul for the whole block or .nav .subs ul li for a single element of the block
example:
.nav .subs li ul
{
max-height: 0;
-moz-transition:1.5s;
-o-transition:1.5s;
-webkit-transition:1.5s;
transition:1.5s;
}
.nav .subs li:hover > ul
{
max-height: 300px;
height: auto;
}
.nav .subs li ul
{
left: 250px;
top: 0;
overflow: hidden;
}
this just shows the new block, if you hover over a submenu-item, now you only have to style it and place it whereever you want it
Example on JSFiddle:
http://jsfiddle.net/4sym7ry0/3/
Do Nested Unorderlist and orderedlist inside your ListItem
Check this For More Info :
http://www.thecodingguys.net/blog/css3-create-a-vertical-menu-with-sub-menu

How to align logo next to navigation?

This is what it looks like:
How would I correctly vertically align the navigation with the logo?
HTML:
<div class="menu-nav">
<ul>
<li>Logo</li>
<li>Home</li>
<li>Chat Now</li>
<li>Mobile Chat</li>
<li>Report User</li>
</ul>
</div>
CSS:
.menu-nav {
}
.menu-nav ul li {
display: inline-block;
}
.menu-nav ul li a{
color: #fff;
margin: 10px;
}
.menu-nav ul a.mg {
}
.menu-nav ul li a.logo {
background: url("../img/logo.png") no-repeat;
text-indent: -9999px;
height:60px;
display:block;
width:215px;
padding: 0;
}
You can add a display method named table to the ul tag and then include a display method table-cell with vertical-align:middle to effectively, vertically align your links to the logo.
HTML:
<div class="menu-nav">
<ul class="a">
<li>Logo
</li>
<li class="navItem">Home
</li>
<li class="navItem">Chat Now
</li>
<li class="navItem">Mobile Chat
</li>
<li class="navItem">Report User
</li>
</ul>
</div>
CSS:
.a{
display:table;
}
.a li{
display: table-cell;
vertical-align:middle;
}
Which is better seen through this JSFiddle
EDIT:
You can update your margin by giving the li tags a class and calling that specific class. This can also be found in the JSFiddle above and you can play with it a bit as well.
Please try below code i have just added line-height:60px; for .menu-nav ul li a
HTML :
<div class="menu-nav">
<ul>
<li>Logo</li>
<li>Home</li>
<li>Chat Now</li>
<li>Mobile Chat</li>
<li>Report User</li>
</ul>
</div>
CSS:
.menu-nav {
}
.menu-nav ul li {
display: inline-block;
}
.menu-nav ul li a{
color: #fff;
margin: 10px;
line-height:60px;
}
.menu-nav ul a.mg {
}
.menu-nav ul li a.logo {
background: url("../img/logo.png") no-repeat;
text-indent: -9999px;
height:60px;
display:block;
width:215px;
padding: 0;
}

How to get a vertical submenu instead a horizontal one?

I developed a submenu with CSS & jQuery and my intention was that it was vertical submenu but I´m getting a horizontal menu.
I already tried to "play" with display in CSS but its not working, like #menu ul li ul li a {display: inline-block;}.
Anyone there knows the trick to put this submenu vertical?
My jsfiddle with full example:
http://jsfiddle.net/jcak/9EcnL/7/
My html:
<section id="menu-container">
<nav id="menu">
<ul>
<li>Home
<ul>
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
<li>Link 4</li>
</ul>
</li>
<li>Procuts
<ul>
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
<li>Link 4</li>
</ul>
</li>
<li>About</li>
<li>Contacts</li>
</ul>
</nav>
</section>
My css:
#menu ul li ul li {display: none;}
#menu-container
{
background:green;
width:100%;
height:46px;
float:left;
z-index:7;
}
#menu
{
width:960px;
height:auto;
margin:0 auto 0 auto;
}
#menu ul
{
list-style-type:none;
}
#menu ul li
{
display: inline-block;
float:left;
height:46px;
position: relative;
line-height:46px;
font-weight:300;
}
#menu ul li a
{
text-decoration:none;
color:#ccc;
display:block;
margin-right:5px;
height:46px;
line-height:46px;
padding:0 5px 0 5px;
font-size:20px;
}
#menu ul li a:hover
{
color:#fff;
}
#menu ul li ul {
position: absolute;
left: 0;
-webkit-padding-start: 0;
width: 300px;
}
#menu ul li ul li
{
color:#fff;
}
By default, a ul will be vertical.
The float:left is what is making this whole menu be horizontal instead.
Have a go at removing that and seeing how the menu behaves.
Working Fiddle
#menu ul li
{
display: inline-block;
height:46px;
position: relative;
line-height:46px;
font-weight:300;
}

submenus in css/html

I have got a submenu which expands from a nav menu type object when I hover over it. Right now, my main nav menu looks like so...
<div id= "navbar">
<ul>
<li><a href= "#" class= "navlink" id= "first"> First
<div class= "firstsubmenu">
<ul>
<li> <a href= "#" class="firstsubmenulink"> First sub menu option </li>
<li> <a href= "#" class="firstsubmenulink"> Second sub menu option </li>
etc...
</ul>
</div></a></li>
<li><a href= "#" class= "navlink" id="second"> Second
<div class= "secondsubmenu">
<ul>
..and so on
</ul>
</div>
Right now, my css is looking like
ul
{
list-style-type:none;
margin:0;
padding:0;
overflow:hidden;
}
li
{
float:left;
}
.navlink:link
{
display:block;
width:120px;
text-align:center;
padding:10px;
text-decoration:none;
color:#FFFFFF;
}
.navlink:hover
{
background-color:#ADD8E6;
color:#FFFFFF;
}
.navlink:visited
{
background-color:#ADD8E6;
color:#FFFFFF;
}
Before I tried making each item in the submenu a clickable link, everything showed up perfectly fine. IE: firstsubmenu showed up perfectly. It's css is
.firstsubmenu
{
display : none;
position : absolute;
left : 75px;
top : 32px ;
background-color : red;
width : 930px;
height : 25px;
z-index : 10;
}
But now that I added the links (made every list element within an block), firstsubmenu no longer appears.
The css for each link looked something like this
.firstsubmenulink
{
display:block;
width:120px;
text-align:center;
padding:10px;
text-decoration:none;
color:#FFFFFF;
}
But as I said, the submenu no longer even appears. I realize this is a bit of a long post, but any advice would be great.
You can use the below css and create pure css based menu.
Css:
body { padding: 3em; }
#navbar * { padding:0; margin: 0; font: 1em arial; }
#navbar { position: absolute; z-index: 99; margin: 0 auto; float: left; line-height: 20px; }
#navbar a { display: block; border: 1px solid #fff; background: #EFBE37; text-decoration: none; padding: 3px 10px; color:#666666; }
#navbar a:hover { background: #C6991D; }
#navbar ul li, #navbar ul li ul li { width: 120px; list-style-type:none; }
#navbar ul li { float: left; width: 120px; }
#navbar ul li ul, #navbar:hover ul li ul, #navbar:hover ul li:hover ul li ul{
display:none;
list-style-type:none;
width: 120px;
}
#navbar:hover ul, #navbar:hover ul li:hover ul, #navbar:hover ul li:hover ul li:hover ul {
display:block;
}
#navbar:hover ul li:hover ul li:hover ul {
position: absolute;
margin-left: 120px;
margin-top: -20px;
}
Structure:
<div id="navbar">
<ul>
<li>Home</li>
<li>Abous Us »
<ul>
<li>About us 1</li>
<li>About us 2 »
<ul>
<li>XXX
<li>XXX
<li>XXX
</ul>
</li>
</ul>
</li>
<li>Download</li>
<li>Menus »
<ul>
<li>Menus 1</li>
<li>Menus 2 »
<ul>
<li>Menus 2-1
<li>Menus 2-2
<li>Menus 2-3
</ul>
</li>
</ul>
</li>
<li>Contact</li>
<li>Feedback</li>
</ul>
jsBin live demo
I had to fix lot of errors in your HTML. Here is the css:
#navbar ul{
list-style:none;
margin:0; padding:0;
display:table;
}
#navbar li{
top:0px;
background:#bbf;
display:inline-block;
width:100px;
}
#navbar li ul li{
display:none;
}
#navbar li:hover li{
display:block;
}
And the fixed HTML:
<div id="navbar">
<ul>
<li>
First
<ul class="firstsubmenu">
<li>1. option</li>
<li>2. option</li>
</ul>
</li>
<li>
Second
<ul class="secondsubmenu">
<li>1. option</li>
<li>2. option</li>
</ul>
</li>
</ul>
</div>
Now, after it works, do with colors whatever you want.
Use also alt tags in your links and images, it improves your SEO and compilance.