Css nav submenu mobile don't work - html

I'm building a nav menu with sub-menus with just CSS (media queries too) and html.
It works fine visualy, but the problem is:
On the mobile browser, When I click in any sub-menu, it won't work, sometimes it just redirect to the first menu address and sometimes it don't even redirect. On the computer browser it works fine too.
Here is my code:
#nav{
position: relative;
height: 100%;
}
#nav ul{
margin: 0px;
padding: 0px;
height: 100%;
}
#nav ul li{
list-style: none;
float: left;
height: 100%;
border-right: black solid 2px;
text-align: center;
padding: 0px 15px 0px 15px;
}
#nav ul li:hover{
background: #47350e;
}
#nav ul li a{
position: relative;
font-family: 'Oswald';
font-size: 18px;
color: white;
text-transform: uppercase;
text-decoration: none;
top: 15px;
}
#nav ul li a:hover{
}
#nav ul li .children li{
border: 0px;
}
#nav ul li .children li a{
font-size: 13px;
top: 5px;
font-weight: normal;
}
#nav ul li .children li a:hover{
text-decoration: underline;
}
#nav ul li .children{
display: none;
position: absolute;
left: 0px;
top: 46px;
height: 30px;
width: 100%;
background: #47350e;
padding-left: 120px;
z-index: 5;
}
#nav ul li:hover .children{
display: block;
}
and HTML
<div id="nav">
<ul id="nav-items">
<li>
<a href=#>option 1</a>
</li>
<li>
<a href=#>option 2</a>
<ul class="children">
<li>
<a href=#>option 3</a>
</li>
<li>
<a href=#>option 4</a>
</li>
</ul>
</li>
</ul>
</div>

For mobile Version u can use Select menu.
<div id="mobile_menu">
<select>
<option>option1</option>
<option>option2</option>
<option>option3</option>
</select>
</div>
CSS is
In normal css
#mobile_menu{display:none;}
For mobile
#media only screen and (min-width: 320px) and (max-width: 479px) {
#mobile_menu{display:block;}
#nav{display:none;}
}

Possibly your #nav ul li a { rule is creating the mess.
position: relative;
top: 15px;
is working for both the levels, i.e. option 1 and option 3
Check if this is the issue. If do not resolve please share the link to your code.

Related

Why is my text-align : center not working in my dropdown menu?

I'm trying to create a drop-down menu but my text-align command wouldn't seem to work (same applies with font-size and other text-related codes). I tried putting my text-align codes in nav ul li and nothing seem to happen. I've also tried putting it on the main .drop-down menu on CSS but it still has no changes. Can anyone help me out here? I couldn't figure out the reasoning behind this.
My HTML and CSS codes are:
nav{
flex:1;
text-align: right;
}
nav ul li{
list-style: none;
display: inline-block;
margin-left: 60px;
position: relative;
}
nav ul li a{
text-decoration: none;
color: #fff;
font-size: 13px;
transition: all 0.5s;
}
nav ul li a:hover{
color: #E6C7F3;
}
.dropdown-menu{
display: none;
}
nav ul li:hover .dropdown-menu {
display: block;
position: absolute;
left: -35;
top: 100%;
width: 100px;
background-color:black;
opacity: .8;
border-radius: 10px;
}
.dropdown-menu ul{
display: block;
padding-top: 10px;
}
.dropdown-menu ul li{
width: 0px;
left: -58;
bottom: 5;
padding: 10px;
padding-right: 40px;
text-align: center;
}
<div class="navbar">
<img src="image/durra.png" class="logo">
<nav>
<ul>
<li>HOME</li>
<li>ABOUT US</li>
<li>SHOP
<div class="dropdown-menu">
<ul>
<li>Bestsellers</li>
<li>Accessories</li>
<li>Jewelry</li>
<li>Miscellaneous</li>
</ul>
</div>
</li>
<li>FEEDBACK</li>
<li>CONTACT</li>
</ul>
</nav>
</div>
text-align works with a element having width. But you have used width: 0px . So it's pretty obvious you cannot use alignment there.
Hi First you have to add padding to ul under dropdown-menu. and then set width of li item to 100%. Please refer below code.
.dropdown-menu ul {
display: block;
padding-top: 10px;
padding: 10px 0 0;
}
.dropdown-menu ul li {
width: 100%;
left: -58;
bottom: 5;
padding: 10px 0;
/* padding-right: 40px; */
text-align: center;
}

separate main nav links from sub nav links in css?

I'm trying to create a dropdown menu for my personal website but something doesn't seem to go right.
HTML:
<header class="mainheader">
<nav class="nav">
<ul>
<li>Home</li><li>
League</li><li>
<ul class="nav-dropdown">
<li>bbva</li>
<li>barclays premier league</li>
</ul>
Contact</li>
</ul>
</nav>
</header>
CSS:
.mainheader, .header-text, .header-text-soccer {
background-color: green;
margin-left: 60px;
margin-right: 60px;
margin-top: 20px;
height: 60px;
border-radius: 6px;
}
.mainheader nav ul li a {
text-decoration: none;
color: white;
}
.mainheader nav ul li {
display: inline-block;
padding: 20px;
color: white;
}
.nav ul li:hover {
background-color: #41a608;
height: 20px;
border-radius: 2px;
}
The last few lines of code are the problem I think. The hover part covers every line-item that is within the .nav , but I don't know how to seperate the main navigation links from the sub navigation links (which should drop down) in css.
Can anyone explain to me what code I should add to let it work?
thanks.
I modified your complete code:
Here is it, There are several modification. This is may be helpful for you. You need to hide your drop-down option first and find out the time when firing it out and also how to fire.
And one important thing, you have to set your drop-down options as absolute, so that it is the child of some main option/ menu.
Modified HTML:
<header class="mainheader">
<nav class="nav">
<ul>
<li>Home</li>
<li>
League
</li>
<li>Dropdown
<ul class="nav-dropdown">
<li>bbva</li>
<li>barclays premier league</li>
</ul>
</li>
<li>Contact</li>
</ul>
</nav>
</header>
Modified CSS:
.mainheader, .header-text, .header-text-soccer {
background-color: green;
margin-left: 60px;
margin-right: 60px;
margin-top: 20px;
height: 60px;
border-radius: 6px;
position: relative;
}
.mainheader nav ul li a {
text-decoration: none;
color: white;
}
.mainheader nav ul li ul{
display: none;
}
.mainheader nav ul li {
display: inline-flex;
padding: 20px;
color: white;
}
.nav ul li:hover {
background-color: #41a608;
border-radius: 2px;
}
.nav ul li:hover ul{
background: #aaa none repeat scroll 0 0;
display: block;
margin-left: -20px;
padding: 0;
position: absolute;
top: 60px;
width: 200px;
}
.mainheader nav ul li ul li{
box-sizing: border-box;
color: white;
display: inline-block;
padding: 20px;
width: 100%;
}
I suppose this is what you need:
https://jsfiddle.net/8f2hvdfh/1/
Your CSS was a mess. Check out a guide on how to make CSS dropdown menus: http://www.w3schools.com/css/css_dropdowns.asp
This gives you the basic setup:
nav ul ul {
position:absolute;
display:none;
padding-left:0;
}
nav ul li {
display:inline-block;
height:60px;
}
nav ul ul li {
display:block;
}
nav ul li a {
text-decoration:none;
color:white;
display:block;
padding:21px;
}
nav ul li:hover ul {
display:block;
}
The rest is bells and whistles. Good luck.

Drop down menu doesn't work

I made a wordpress template with a simple CSS drop down menu. The code I used is a code that I used regularly, but this time when you hover on the button and than wants to hover on the drop down menu that appears, the drop down menu will disappear.
Does somebody know how I can solve this problem and what's wrong?
Link to template: http://bit.ly/1Ivcg2U
#navigation ul {
list-style: none;
width: 800px;
height: 40px;
padding: 0;
margin: 0 auto;
}
#navigation li {
float: left;
position: relative;
z-index: 500;
display: block;
text-align: center;
margin: 0px 40px;
padding: 5px;
}
#navigation li ul {
display: none;
position: absolute;
max-width: 140px;
top: 40px;
left: -20px;
}
ul#categories li {
width: 100%;
float: left;
margin: 0;
background: #fff;
}
ul#categories a {
padding: 10px;
width: 200px;
}
ul#categories li:hover{
background: #000;
}
ul#navigation li:hover > ul,
#navigation ul li:hover > ul {
display: block; /* display the dropdown */
}
#navigation a {
font-family: 'Montserrat';
color: #474747;
text-decoration: none;
font-weight: 300;
letter-spacing: 2px;
text-transform: uppercase;
font-size: 10px;
}
li a:hover {
color: #000;
font-family: 'Montserrat';
}
ul#categories li a:hover {
color: #fff;
}
<div id="bar">
<div id="navigation">
<ul id="nav">
<li>Home</li>
<li>
Categorieën
<ul id="categories">
<li>travel</li>
<li>Beauty</li>
<li>Fashion</li>
<li>Lifestyle</li>
<li>Persoonlijk</li>
<div class="clear"></div>
</ul>
</li>
<li>
Over mij
<div class="clear"></div>
</li>
<li>
Contact
<div class="clear"></div>
</li>
<li>
Zakelijk
<div class="clear"></div>
</li>
</ul>
</div>
The problem is that your 2nd level menu is too low from your top level :
#navigation li ul {
display: none;
position: absolute;
max-width: 140px;
top: 40px;/* Change this to a lower value so it overlaps or doesn't leave a gap with menu above*/
left: -20px;
}
When the cursor moves to the gap, it's no longer at the 'hover' state, so the dropdown disappears. Reducing the gap will fix the problem.

CSS dropdown menu errors- can't target a specific element

Trying to make just the services link orange on hover with a gray background- can't do it without changing all the menu items.
I can't click on the examples link after hovering over services.
.menu
{
margin:0;
padding:0;
}
.menu ul {
padding-top: 40px;
padding-left: 0px;
line-height: 0px;
margin-bottom: 0px;
float: right;
}
ul li {
display: inline;
}
ul li a:visited {
text-decoration: none;
}
ul li a:hover, .menu ul li .current{
color: #f7823b;
}
ul li {
display: block;
position: relative;
float: left;
}
li ul { display: none; }
ul li a {
float: left;
font-size: 20px;
display: block;
text-decoration: none;
color: #ffffff;
padding: 20px;
margin-left: 1px;
white-space: nowrap;
}
li:hover ul {
display: block;
}
li:hover li {
float: none;
font-size: 11px;
}
ul ul li:hover a { background: #818285; }
/*li:hover li a:hover { background: #818285; width:100%; }*/
ul ul {
position: absolute;
z-index: 500;
margin:0;
padding-top: 0px;
}
ul ul li a
{
padding: 20px 0px 20px 5px;
width: 100%;
background: #818285;
}
<div class="socialmedia">
<img class="button" src="http://lifeafterclass.com/cyclone/images/header/facebook.png" <="" img="">
<img class="button" src="http://lifeafterclass.com/cyclone/images/header/twitter.png" <="" img="">
<a href="http://www.stumbleupon.com/stumbler/CyclonStrategies">
<img class="button" src="http://lifeafterclass.com/cyclone/images/header/stumbleupon.png" <="" img=""></a>
<a href="http://www.linkedin.com/company/cyclone-strategies-llc">
<img class="button" src="http://lifeafterclass.com/cyclone/images/header/linkedin.png" <="" img=""></a>
</div>
<div class="menu">
<ul id="menu">
<li>Home</li>
<li> About</li>
<li class="special"> Services
<ul>
<li>Digital Advertising</li>
<li>Promotion Management</li>
<li>Social Media</li>
</ul>
</li>
<li>Examples</li>
<li> Blog </li>
<li> Contact Us</li>
</ul>
</div>
<div style="clear:both"></div>
</div>
I've tried everything- any help is appreciated. Thanks!
http://jsfiddle.net/8ARm5/
Since the li containing services has a class special you can use this to target the element upon hover.
.special:hover{
color: orange;
background: grey;
}
Try to add hover on li not a element:
li:hover > a {
color: #f7823b;
}
Doing so the link keeps style definition even if you points links in submenu.
Take a look: http://jsfiddle.net/8ARm5/5/

Drop down menu hover does not cover whole text

Screenshot1:
Screenshot 2:
If you look at the screenshot1, you can see when you hover over web design it doesn't completely change the background color. However it does in case you hover over text 'Search Engine' in Screenshot 2.
Here is the markup:
Html:
<div id="nav">
<ul>
<li><a href="#" >My Health</a></li>
<li><a href="#" >Fitness</a></li>
<li><a href="#" >Diet & Nutrition</a>
<ul>
<li>Webdesign</li>
<li>Development</li>
<li>Illustration</li>
<li>Search engine</li>
<li>WordPress</li>
</ul>
</li>
<li>Stress Management</li>
</ul>
</div>
CSS:
#nav {
width: 100%;
height: 36px;
background: url('../images/nav-bg.png') repeat;
margin-bottom: 10px;
}
#nav ul li a{
display: block;
float: left;
font: bold 15px Arial, Helvetica, sans-serif;
color: #FFFFFF;
padding: 9px 14px;
}
#nav ul li a:hover{
color: #355da5;
background: #fff;
border: medium black;
}
#nav ul li ul{
display: none;
position: absolute;
top: 130px;
margin: 8px 0px 0px 180px;
background: url('../images/nav-bg.png') repeat;
}
#nav ul li ul li a{
text-align: center;
font-size: 12px;
}
#nav ul li:hover ul, li.over ul{
display: block;
}
Does anyone know how can i fix this?
Thank you.
Try setting width: 100% on #nav ul li a.
your nested <a> tags are matched by the css selector #nav ul li a, and are therefore floated left.
try adding float:none; inside #nav ul li ul li a