I am building a site and I am stuck with a problem... when I hover over a li element and the submenu is displayed, I can't click anything inside it because it closes really fast.
Code added below -
<div class="col-md-9">
<ul>
<li>Home</li>
<li>Order
<ul class="submenu1" style="margin-left: -35px">
<li><center>Order Entry<hr/></center></li>
<li><center>Shipment Details<hr/></center></li>
<li><center>Accounts Department<hr/></center></li>
<li><center>Machine Installation Group<hr/></center></li>
<li><center>Commercial Group<hr/></center></li>
<li><center>Order Enquiry<hr/></center></li>
<li><center>Order Status<hr/></center></li>
</ul>
</li>
</ul>
</div>
.nav
{
height:100px;
background-color:darkslateblue;
}
.image
{
height:400px;
background-image: url('../images/image.png');
background-repeat: no-repeat;
background-size:cover;
}
.image h1
{
color:white;
margin-left:150px;
text-align: center;
font-size:25px;
font-family: 'Raleway', sans-serif;
text-transform: uppercase;
font-weight:bold;
padding-top:150px;
}
.nav a
{
color:white;
font-family: 'Raleway', sans-serif;
font-weight:600;
font-size:12px;
text-transform:uppercase;
padding:20px;
}
.nav li
{
display:inline;
}
.nav .container
{
padding:30px;
}
.menu2
{
height:50px;
background-color: darkslateblue;
}
.info
{
height:400px;
background-color: white;
}
.info h1
{
color: darkslateblue;
text-align:center;
font-size:50px;
font-family: 'Raleway', sans-serif;
text-transform: uppercase;
font-weight:bold;
padding-top:25px;
}
.info p
{
color: black;
font-family: 'Raleway', sans-serif;
margin: 50px;
font-size:20px;
font-weight:bold;
}
.footer
{
height:50px;
background-color:darkslateblue;
}
.footer p
{
color:white;
text-transform: uppercase;
padding:10px;
}
.setPass
{
margin-top:60px;
margin-left:500px;
}
.submenu1
{
width:200px;
height:450px;
border: 1px solid darkslateblue;
display: none;
background-color: darkslateblue;
margin-top: 44px;
}
.submenu1 ul
{
display:none;
position:absolute;
}
.submenu1 ul li a
{
color:white;
font-family: 'Raleway', sans-serif;
font-size:12px;
text-transform:uppercase;
}
.col-md-9 ul li:hover .submenu1
{
display:block;
position:absolute;
}
.submenu2
{
width:200px;
height:230px;
border: 1px solid darkslateblue;
display: none;
background-color: darkslateblue;
margin-top: 44px;
}
.submenu2 ul
{
display:none;
position:absolute;
}
.submenu2 ul li a
{
color:white;
font-family: 'Raleway', sans-serif;
font-size:12px;
text-transform:uppercase;
}
.col-md-9 ul li:hover .submenu2
{
display:block;
position:absolute;
}
.submenu3
{
width:200px;
height:300px;
border: 1px solid darkslateblue;
display: none;
background-color: darkslateblue;
margin-top: 44px;
}
.submenu3 ul
{
display:none;
position:absolute;
}
.submenu3 ul li a
{
color:white;
font-family: 'Raleway', sans-serif;
font-size:12px;
text-transform:uppercase;
}
.col-md-9 ul li:hover .submenu3
{
display:block;
position:absolute;
}
.submenu4
{
width:200px;
height:110px;
border: 1px solid darkslateblue;
display: none;
background-color: darkslateblue;
margin-top: 44px;
}
.submenu4 ul
{
display:none;
position:absolute;
}
.submenu4 ul li a
{
color:white;
font-family: 'Raleway', sans-serif;
font-size:12px;
text-transform:uppercase;
}
.col-md-9 ul li:hover .submenu4
{
display:block;
position:absolute;
}
I know that there is a gap but i'm not able to remove it.
Please help.
Thanks in advance.
You dirty code that is difficult to maintain in the future
Try to take out the styles in the css
*{
padding: 0;
margin: 0;
box-sizing: border-box;
/* use reset.css or normalize.css */
}
ul{
list-style: none;
display: flex;
}
ul> li{
position: relative;
}
ul> li a{
display: block;
padding: 5px 10px;
}
.submenu{
display: none;
position: absolute; top: 100%; left: 0;
}
ul> li:hover .submenu{
display: block;
}
<ul>
<li>Home</li>
<li>Order
<ul class="submenu">
<li>Order Entry</li>
<li>Shipment Details</li>
<li>Accounts Department</li>
<li>Machine Installation Group</li>
<li>Commercial Group</li>
<li>Order Enquiry</li>
<li>Order Status</li>
</ul>
</li>
</ul>
Delete margin-top: 44px from class submenu1 and other submenus
Fiddle: https://jsfiddle.net/7mnu4Lcx/1/
Related
I'm doing my project for web development and my friend was assigned to do the nav bar. But after i completed my website and pasted his nav bar codes into my codes. It clashed with my bootstrap and thus not displaying correctly. I tried searching for solutions like pasting the link ref after the bootstrap but still up to no avail.
I'll put the CSS code and HTML code here. I'm guessing the classes clashed?
<nav class="navbar">
<ul>
<li><a class="donation" border= href="#donate">DONATE</a></li>
<li class="dropdown">
EVENTS
<div id="specificdays" class="dropdown-content">
World Environment Day
World Ocean Day
World Clean Up Day
World Day to combat Desertification and Drought
</div>
</li>
<li class="dropdown">
PROJECTS
<div class="dropdown-content">
Reward System
Comic Strips & Posters
Make A Pledge
Why a Greenboy
Donate to a cause
</div>
</li>
<li><a id="maintopic" href="#about">ABOUT</a></li>
<li id="logo"><img src="eugene.png" class="logo"></li>
</ul>
</nav>
/CSS/
*{
margin-top:0;
margin-left:0;
margin-right:0;
}
#mainpage{
width:100%;
height:650px;
}
#logo{
float:left;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
nav{
position:sticky;
top:0;
z-index:1;
}
li {
float: right;
text-align:center;
padding-right:40px;
padding-top:10px;
display:block;
}
li a, .dropbtn {
display: inline-block;
color: #fff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-family:quicksand;
margin-top:5px;
margin-right:-10px;
}
#maintopic{
letter-spacing: 4px;
font-size:13px;
}
.donation{
border:1;
border-size:1px;
letter-spacing: 4px;
font-size:13px;
border-color:#333;
border-style:solid;
cursor:pointer;
border-color:white;
padding:10px 10px 10px 10px;
}
.donation:hover{
background-color:#fff;
color:#333;
}
#maintopic:hover{
border-bottom:2px solid #fff;
}
li .dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display:block;
text-align: left;
width:128px;
}
#specificdays a{
width:200px;
}
#specificdays a:hover{
width:190px;
}
.dropdown-content a:hover {
background-color: #333;
color:#ddd ;
}
.dropdown:hover .dropdown-content {
display:block;
}
.navbar{
padding:3px;
text-align:center;
color: black;
font-family: sans-serif;
background-color: #333;
}
.logo{
width:140px;
height:60px;
cursor: pointer;
margin-top:-25px;
margin-bottom:-10px;
}
Just rename your class with any unique name which will not be in Bootstrap.For that you can add your website name with class or anything
<nav class="your-theme-navbar">
<ul>
<li><a class="donation" border= href="#donate">DONATE</a></li>
<li class="your-theme-dropdown">
EVENTS
<div id="specificdays" class="your-theme-dropdown-content">
World Environment Day
World Ocean Day
World Clean Up Day
World Day to combat Desertification and Drought
</div>
</li>
<li class="your-theme-dropdown">
PROJECTS
<div class="your-theme-dropdown-content">
Reward System
Comic Strips & Posters
Make A Pledge
Why a Greenboy
Donate to a cause
</div>
</li>
<li><a id="maintopic" href="#about">ABOUT</a></li>
<li id="logo"><img src="eugene.png" class="your-theme-logo"></li>
</ul>
and change these classes in CSS also
*{
margin-top:0;
margin-left:0;
margin-right:0;
}
#mainpage{
width:100%;
height:650px;
}
#logo{
float:left;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
nav{
position:sticky;
top:0;
z-index:1;
}
li {
float: right;
text-align:center;
padding-right:40px;
padding-top:10px;
display:block;
}
li a, .dropbtn {
display: inline-block;
color: #fff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-family:quicksand;
margin-top:5px;
margin-right:-10px;
}
#maintopic{
letter-spacing: 4px;
font-size:13px;
}
.donation{
border:1;
border-size:1px;
letter-spacing: 4px;
font-size:13px;
border-color:#333;
border-style:solid;
cursor:pointer;
border-color:white;
padding:10px 10px 10px 10px;
}
.donation:hover{
background-color:#fff;
color:#333;
}
#maintopic:hover{
border-bottom:2px solid #fff;
}
li .your-theme-dropdown {
display: inline-block;
}
.your-theme-dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.your-theme-dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display:block;
text-align: left;
width:128px;
}
#specificdays a{
width:200px;
}
#specificdays a:hover{
width:190px;
}
.your-theme-dropdown-content a:hover {
background-color: #333;
color:#ddd ;
}
.your-theme-dropdown:hover .your-theme-dropdown-content {
display:block;
}
.your-theme-navbar{
padding:3px;
text-align:center;
color: black;
font-family: sans-serif;
background-color: #333;
}
.your-theme-logo{
width:140px;
height:60px;
cursor: pointer;
margin-top:-25px;
margin-bottom:-10px;
}
Change the name of your defined classes, for example .navbar class in your css file is already included in css file of bootstrap.
If you want use some css of bootstrap and some custom css then just write new class nearby navbar class and target all navbar css with that new class
example
*{
margin-top:0;
margin-left:0;
margin-right:0;
}
#mainpage{
width:100%;
height:650px;
}
#logo{
float:left;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
nav.custom-navbar{
position:sticky;
top:0;
z-index:1;
}
.custom-navbar ul li {
float: right;
text-align:center;
padding-right:40px;
padding-top:10px;
display:block;
}
.custom-navbar ul li a,.custom-navbar ul li a.dropbtn {
display: inline-block;
color: #fff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-family:quicksand;
margin-top:5px;
margin-right:-10px;
}
#maintopic{
letter-spacing: 4px;
font-size:13px;
}
.donation{
border:1;
border-size:1px;
letter-spacing: 4px;
font-size:13px;
border-color:#333;
border-style:solid;
cursor:pointer;
border-color:white;
padding:10px 10px 10px 10px;
}
.donation:hover{
background-color:#fff;
color:#333;
}
#maintopic:hover{
border-bottom:2px solid #fff;
}
.custom-navbar ul li .dropdown {
display: inline-block;
}
.custom-navbar ul li .dropdown .dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.custom-navbar ul li .dropdown .dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display:block;
text-align: left;
width:128px;
}
#specificdays a{
width:200px;
}
#specificdays a:hover{
width:190px;
}
.custom-navbar ul li .dropdown .dropdown-content a:hover {
background-color: #333;
color:#ddd ;
}
.custom-navbar ul li .dropdown:hover .dropdown-content {
display:block;
}
.custom-navbar.navbar{
padding:3px;
text-align:center;
color: black;
font-family: sans-serif;
background-color: #333;
}
.logo{
width:140px;
height:60px;
cursor: pointer;
margin-top:-25px;
margin-bottom:-10px;
}
<nav class="navbar custom-navbar">
<ul>
<li><a class="donation" border= href="#donate">DONATE</a></li>
<li class="dropdown">
EVENTS
<div id="specificdays" class="dropdown-content">
World Environment Day
World Ocean Day
World Clean Up Day
World Day to combat Desertification and Drought
</div>
</li>
<li class="dropdown">
PROJECTS
<div class="dropdown-content">
Reward System
Comic Strips & Posters
Make A Pledge
Why a Greenboy
Donate to a cause
</div>
</li>
<li><a id="maintopic" href="#about">ABOUT</a></li>
<li id="logo"><img src="eugene.png" class="logo"></li>
</ul>
</nav>
I'm building a menu for my site but for some reason the "event" when i hover over a item does not trigger the class to be activated. Also the active class won't display either
Summary:
1.On_Hover wont work
2.Active wont either
The relevant code is here
#font-face {font-family: Futura; src: url('FuturaOriginal.ttf');}
#font-face {font-family: FuturaLight; src: url('FuturaLight.ttf');}
#font-face {font-family: FuturaBold; src: url('FuturaBold.ttf');}
BODY {
font-family: FuturaLight;
background: white; color: #333;
align-content: top;
margin: 0;
padding: 0;
}
.margin {
margin-left: 300px;
margin-right: 300px;
}
#primary_nav_wrap
{
margin-top:100px;
text-align: center;
position: fixed;
width: 100%;
color: white;
border-bottom: 5px solid darkgreen;
background-color: #FFDE46;
}
#primary_nav_wrap ul
{
list-style:none;
position:relative;
display: inline-block;
margin:0;
padding:0;
color: darkgreen;
}
#primary_nav_wrap ul a
{
display:block;
color: white;
text-decoration:none;
font-weight:700;
font-size:20px;
line-height:32px;
padding:0 15px;
font-family: FuturaBold;
color: white;
background-color: darkgreen;
}
#primary_nav_wrap ul li
{
position:relative;
float:left;
margin:0;
padding:0;
color: white;
}
#primary_nav_wrap ul li.current-menu-item
{
background-color: lawngreen;
color: white;
}
#primary_nav_wrap ul li:hover
{
background-color: black;
color: white;
}
#primary_nav_wrap ul ul
{
display:none;
position:absolute;
top:100%;
left:0;
background-color: white;
color: darkgreen;
padding:0;
}
#primary_nav_wrap ul ul li
{
float:none;
width:200px;
border: 1px solid #FFDE46;
color: White;
}
#primary_nav_wrap ul ul a
{
line-height:120%;
padding:10px 15px;
color: White;
}
#primary_nav_wrap ul ul ul
{
top:0;
left:100%;
color: white;
}
#primary_nav_wrap ul li:hover > ul
{
display:block;
}
.spacer
{
width: 100%;
height: 110px;
}
.side
{
position: fixed;
width: 250px;
border-right-style: solid;
border-width: 5px;
height: 100%;
align-self: left;
float: left;
}
.main
{
width: 100%;
float: left;
}
H1 {
font-size: 60px;
margin-top: 0;
padding-bottom: 50px;
padding-top: 1px;
text-align: center;
list-style-type: none;
position: fixed;
width: 100%;
top: 0;
font-family: FuturaBold;
color: green;
background-color: #FFDE46;
}
/*Opmaak van je header2*/
H2 {
font-family: Futura;
font-size: 40px;
/*Kleur toevoegen*/
color: darkgreen;
/*Tekst centreren*/
text-align:center;
}
/*Opmaak header3*/
H3 {
font-family: Futura;
/*Kleur toevoegen*/
font-size:30px;
color: darkgreen
}
p.futura20{
font-family: Futura;
font-size: 16px
}
p.futura25{
font-family: Futura;
font-size: 20px
}
.spacer2
{
height: 10px;
}
#footer {
margin-bottom: 0px;
align-self: bottom;
height: 200px;
background-color: #FFDE46;
position: relative;
}
.scoutsgidsen {
height: 150px;
position: absolute;
left: 300px;
bottom: 20px;
}
.logo {
height: 150px;
position: absolute;
right: 300px;
bottom: 20px;
}
.avondlied {
font-family: Futura;
font-size: 18px;
text-align: center;
font-weight: 800;
}
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>Scouts Permeke</TITLE>
<link rel="stylesheet" type="text/css" href="siteStyle.css">
</HEAD>
<BODY>
<H1>Scouts Permeke</H1>
<nav id="primary_nav_wrap">
<ul>
<li class="current-menu-item">Home</li>
<li>Nieuws</li>
<li>Takken ▼
<ul>
<li>Kapoenen (6-8 jaar)</li>
<li>Kawellen (8-11 jaar)</li>
<li>Jonggivers (11-14 jaar)</li>
<li>Givers (14-17 jaar)</li>
<li>Jin, leiding en VT (+17 jaar)</li>
</ul>
</li>
<li>Activiteiten ▼
<ul>
<li>Kapoenen</li>
<li>Kawellen</li>
<li>Jonggivers</li>
<li>Givers</li>
</ul>
</li>
<li>Praktisch ▼
<ul>
<li>Taf & Toetje</li>
<li>Papierwerk</li>
<li>Uniform</li>
<li>Technieken</li>
<li>Jaarthema</li>
<li>Rituelen</li>
</ul>
</li>
<li>Algemeen</li>
<li>Over</li>
<li>Foto's</li>
<li>Inschrijven</li>
<li>Verhuur</li>
<li>Contact</li>
</ul>
</nav>
<div class="spacer">
</div>
<img src="groepsfoto.jpg" width="100%"" >
<div style="font-family: Futura">
<H2>Welkom op onze vernieuwde site!</H2>
<H2>Kijk gerust even rond.</H2>
</div>
<div class="spacer2"></div>
</div>
<div id="footer">
<img src="logo_Scouts_en_Gidsen_Vlaanderen.png" class="scoutsgidsen"/>
<img src="logo.png" class="logo"/>
</div>
</BODY>
</HTML>
You are applying the hover rule to the li, but that's covered by the a elements, therefore the background color change won't be visible. So it's better to applly the hover rule to the a elements:
#primary_nav_wrap ul li a:hover instead of #primary_nav_wrap ul li:hover
Similarly with .current-menu-item(I suppose that's what you mean by "active class":
#primary_nav_wrap ul li.current-menu-item a
{
background-color: lawngreen;
color: white;
}
#font-face {font-family: Futura; src: url('FuturaOriginal.ttf');}
#font-face {font-family: FuturaLight; src: url('FuturaLight.ttf');}
#font-face {font-family: FuturaBold; src: url('FuturaBold.ttf');}
BODY {
font-family: FuturaLight;
background: white; color: #333;
align-content: top;
margin: 0;
padding: 0;
}
.margin {
margin-left: 300px;
margin-right: 300px;
}
#primary_nav_wrap
{
margin-top:100px;
text-align: center;
position: fixed;
width: 100%;
color: white;
border-bottom: 5px solid darkgreen;
background-color: #FFDE46;
}
#primary_nav_wrap ul
{
list-style:none;
position:relative;
display: inline-block;
margin:0;
padding:0;
color: darkgreen;
}
#primary_nav_wrap ul a
{
display:block;
color: white;
text-decoration:none;
font-weight:700;
font-size:20px;
line-height:32px;
padding:0 15px;
font-family: FuturaBold;
color: white;
background-color: darkgreen;
}
#primary_nav_wrap ul li
{
position:relative;
float:left;
margin:0;
padding:0;
color: white;
}
#primary_nav_wrap ul li.current-menu-item a
{
background-color: lawngreen;
color: white;
}
#primary_nav_wrap ul li a:hover
{
background-color: black;
color: white;
}
#primary_nav_wrap ul ul
{
display:none;
position:absolute;
top:100%;
left:0;
background-color: white;
color: darkgreen;
padding:0;
}
#primary_nav_wrap ul ul li
{
float:none;
width:200px;
border: 1px solid #FFDE46;
color: White;
}
#primary_nav_wrap ul ul a
{
line-height:120%;
padding:10px 15px;
color: White;
}
#primary_nav_wrap ul ul ul
{
top:0;
left:100%;
color: white;
}
#primary_nav_wrap ul li:hover > ul
{
display:block;
}
.spacer
{
width: 100%;
height: 110px;
}
.side
{
position: fixed;
width: 250px;
border-right-style: solid;
border-width: 5px;
height: 100%;
align-self: left;
float: left;
}
.main
{
width: 100%;
float: left;
}
H1 {
font-size: 60px;
margin-top: 0;
padding-bottom: 50px;
padding-top: 1px;
text-align: center;
list-style-type: none;
position: fixed;
width: 100%;
top: 0;
font-family: FuturaBold;
color: green;
background-color: #FFDE46;
}
/*Opmaak van je header2*/
H2 {
font-family: Futura;
font-size: 40px;
/*Kleur toevoegen*/
color: darkgreen;
/*Tekst centreren*/
text-align:center;
}
/*Opmaak header3*/
H3 {
font-family: Futura;
/*Kleur toevoegen*/
font-size:30px;
color: darkgreen
}
p.futura20{
font-family: Futura;
font-size: 16px
}
p.futura25{
font-family: Futura;
font-size: 20px
}
.spacer2
{
height: 10px;
}
#footer {
margin-bottom: 0px;
align-self: bottom;
height: 200px;
background-color: #FFDE46;
position: relative;
}
.scoutsgidsen {
height: 150px;
position: absolute;
left: 300px;
bottom: 20px;
}
.logo {
height: 150px;
position: absolute;
right: 300px;
bottom: 20px;
}
.avondlied {
font-family: Futura;
font-size: 18px;
text-align: center;
font-weight: 800;
}
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>Scouts Permeke</TITLE>
<link rel="stylesheet" type="text/css" href="siteStyle.css">
</HEAD>
<BODY>
<H1>Scouts Permeke</H1>
<nav id="primary_nav_wrap">
<ul>
<li class="current-menu-item">Home</li>
<li>Nieuws</li>
<li>Takken ▼
<ul>
<li>Kapoenen (6-8 jaar)</li>
<li>Kawellen (8-11 jaar)</li>
<li>Jonggivers (11-14 jaar)</li>
<li>Givers (14-17 jaar)</li>
<li>Jin, leiding en VT (+17 jaar)</li>
</ul>
</li>
<li>Activiteiten ▼
<ul>
<li>Kapoenen</li>
<li>Kawellen</li>
<li>Jonggivers</li>
<li>Givers</li>
</ul>
</li>
<li>Praktisch ▼
<ul>
<li>Taf & Toetje</li>
<li>Papierwerk</li>
<li>Uniform</li>
<li>Technieken</li>
<li>Jaarthema</li>
<li>Rituelen</li>
</ul>
</li>
<li>Algemeen</li>
<li>Over</li>
<li>Foto's</li>
<li>Inschrijven</li>
<li>Verhuur</li>
<li>Contact</li>
</ul>
</nav>
<div class="spacer">
</div>
<img src="groepsfoto.jpg" width="100%"" >
<div style="font-family: Futura">
<H2>Welkom op onze vernieuwde site!</H2>
<H2>Kijk gerust even rond.</H2>
</div>
<div class="spacer2"></div>
</div>
<div id="footer">
<img src="logo_Scouts_en_Gidsen_Vlaanderen.png" class="scoutsgidsen"/>
<img src="logo.png" class="logo"/>
</div>
</BODY>
</HTML>
Currently I have a header and above it I have my navbar. On my editor it is centered but when I stretch the page or view it in a different format it won't appear to be on top of the center of the header. Any ideas on what I should do?
#nav{
list-style-type: none;
position:absolute;
padding: 0;
overflow: hidden;
margin-top:-25px;
margin-left:50px;
}
#nav li{
float:left;
}
#nav a:link, #nav a:visited {
display: block;
width: 120px;
font-weight: bold;
color: #FFFFFF;
background-color: darkorange;
text-align: center;
padding: 4px;
border:2px solid black;
border-top-right-radius:10px;
border-top-left-radius:10px;
text-decoration: none;
text-transform: uppercase;
border-bottom:none;
}
#nav a:hover{
background-color: orangered;
}
#nav a:active{
color:black;
}
#header{
height:150px;
background-color:darkred;
margin-top:45px;
border:2px solid black;
border-radius:15px;
overflow:hidden;
position:relative;
}
#innerheader{
background-color:burlywood;
height:100px;
margin-left:auto;
margin-right:auto;
overflow:hidden;
width:50%;
border-radius:25px;
border:3px solid black;
position:Relative;
margin-top:22px;
}
#innerheader h1{
position:relative;
margin-left:auto;
text-align:center;
margin-top:30px;
-webkit-text-stroke-width:0.6px;
-webkit-text-stroke-color:black;
color:saddlebrown;
}
<body>
<ul id="nav">
<li>Home</li>
<li>Photos</li>
<li>Statistics</li>
<li>Chat</li>
<li> Biography </li>
</ul>
<div id="header">
<div id="innerheader">
<h1>
General Information
</h1>
</div>
</div>
</body>
Much of what I provided will not be useful to this question, and I apologize for that, but I just want to provide as much information as possible to get help. Thanks!
Hi now try to this css
#nav {
list-style-type: none;
padding: 0;
overflow: hidden;
margin: 0 auto;
display: block;
text-align: center;
font-size: 0;
}
#nav li {
display: inline-block; // add this
font-size: 14px; // add this
}
#header {
/* margin-top: 45px; */ // remove this line
}
Demo
#nav {
list-style-type: none;
/* position: absolute; */
padding: 0;
overflow: hidden;
margin: 0 auto;
/* margin-left: 50px; */
display: block;
text-align: center;
font-size: 0;
}
#nav li {
display: inline-block;
font-size: 14px;
}
#header {
height: 150px;
background-color: darkred;
/* margin-top: 45px; */
border: 2px solid black;
border-radius: 15px;
overflow: hidden;
position: relative;
}
#nav a:link, #nav a:visited {
display: block;
width: 120px;
font-weight: bold;
color: #FFFFFF;
background-color: darkorange;
text-align: center;
padding: 4px;
border:2px solid black;
border-top-right-radius:10px;
border-top-left-radius:10px;
text-decoration: none;
text-transform: uppercase;
border-bottom:none;
}
#nav a:hover{
background-color: orangered;
}
#nav a:active{
color:black;
}
#innerheader{
background-color:burlywood;
height:100px;
margin-left:auto;
margin-right:auto;
overflow:hidden;
width:50%;
border-radius:25px;
border:3px solid black;
position:Relative;
margin-top:22px;
}
#innerheader h1{
position:relative;
margin-left:auto;
text-align:center;
margin-top:30px;
-webkit-text-stroke-width:0.6px;
-webkit-text-stroke-color:black;
color:saddlebrown;
}
<body>
<ul id="nav">
<li>Home</li>
<li>Photos</li>
<li>Statistics</li>
<li>Chat</li>
<li> Biography </li>
</ul>
<div id="header">
<div id="innerheader">
<h1>
General Information
</h1>
</div>
</div>
</body>
Add these properties to your existing classes.
#nav{
list-style-type: none;
position:absolute;
padding: 0;
overflow: hidden;
margin-top:-25px;
margin-left:50px;
width:100%;
text-align:center;
}
#nav li{
display:inline-block;
}
This should solve your issue.
Make your nav bar take full width, and center the inner contents horizontally using text-align:center;
This is my css code:
#navigation
{
width: 100%;
height:31px;
background:#333;
}
#navigation ul
{
margin: 0;
padding: 0;
}
#navigation ul li
{
list-style-type: none;
display: inline;
}
#navigation li a
{
display: block;
float: right;
color:#CCC;
text-decoration: none;
padding-top: 7px;
padding-right: 10px;
padding-bottom: 7px;
padding-left: 10px;
font-family: Tahoma, Geneva, sans-serif;
font-size: 14px;
font-weight:bold;
}
#navigation li a:hover
{
color:#FFF;
}
And this is my html code:
<div id="navigation">
<ul>
<li><div>menu1</div></li>
<li><div>menu2</div></li>
<li><div>menu3</div></li>
<li><div>menu4</div></li>
</ul>
</div>
Here every link tag has hover event. But I want to remove hover event for only menu1. I mean user can click on menu2, menu3 and menu4 but menu1 doesn't have hover event so when user click on it, nothing happen.
try this DEMO
#navigation
{
width: 100%;
height:31px;
background:#333;
}
#navigation ul
{
margin: 0;
padding: 0;
}
#navigation ul li
{
list-style-type: none;
display: inline;
}
#navigation li a
{
display: block;
float: right;
color:#CCC;
text-decoration: none;
padding-top: 7px;
padding-right: 10px;
padding-bottom: 7px;
padding-left: 10px;
font-family: Tahoma, Geneva, sans-serif;
font-size: 14px;
font-weight:bold;
}
#navigation li:hover:nth-of-type(2) a
{
color:#FFF;
}
#navigation li:hover:nth-of-type(3) a
{
color:#FFF;
}
#navigation li:hover:nth-of-type(4) a
{
color:#FFF;
}
#navigation li:not(:first-child) a:hover
{
color:#FFF;
}
Fiddle here
For selecting second elements and next, you can use + selector in CSS:
#navigation li + li a:hover
{
color: #FFF;
}
From W3C:
E + F: Matches any F element immediately preceded by a sibling element E.
For disabling the link, you should change your markup, or use JavaScript.
Add a id or class to the first element (The one you dont want to hover)
Add this css to that class or id
#id-you-used:hover {
color: #CCC;
}
.class-you-used:hover {
color: #CCC;
}
Your HTML is broken for first two links
<li><div><a href="">menu1/a></div></li>
<li><div><a href="">menu2/a></div></li>
should be :
<li><div>menu1</div></li>
<li><div>menu2</div></li>
One other easy answer:
css code:
#charset "utf-8";
/* CSS Document */
html, body
{
margin:0;
padding:0;
height:100%;
}
#navigation
{
width: 100%;
height:31px;
background:#333;
}
#navigation ul
{
margin: 0;
padding: 0;
}
#navigation ul li
{
list-style-type: none;
display: inline;
}
#navigation li a
{
display: block;
float: right;
color:#CCC;
text-decoration: none;
padding-top: 7px;
padding-right: 10px;
padding-bottom: 7px;
padding-left: 10px;
font-family: Tahoma, Geneva, sans-serif;
font-size: 14px;
font-weight:bold;
}
#username
{
display: block;
float: left;
color:#CCC;
text-decoration: none;
padding-top: 7px;
padding-right: 10px;
padding-bottom: 7px;
padding-left: 10px;
font-family: Tahoma, Geneva, sans-serif;
font-size: 14px;
font-weight:bold;
background-color:#078415;
}
#navigation a:hover
{
color:#FFF;
}
html code:
<div id="navigation">
<ul>
<li><div id="username">menu1</div></li>
<li><div>menu2</div></li>
<li><div>menu3</div></li>
<li><div>menu4</div></li>
</ul>
</div>
One more easy answer:
css code:
#charset "utf-8";
/* CSS Document */
html, body
{
margin:0;
padding:0;
height:100%;
}
#navigation
{
width: 100%;
height:31px;
background:#333;
}
#navigation ul
{
margin: 0;
padding: 0;
}
#navigation ul li
{
list-style-type: none;
display: inline;
}
#navigation li a
{
display: block;
float: right;
color:#CCC;
text-decoration: none;
padding-top: 7px;
padding-right: 10px;
padding-bottom: 7px;
padding-left: 10px;
font-family: Tahoma, Geneva, sans-serif;
font-size: 14px;
font-weight:bold;
}
#navigation a.active:hover
{
color:#FFF;
}
html code:
<div id="navigation">
<ul>
<li style="float:left; background-color:#055C06;"><div><a>menu1</a></div></li>
<li style="float:left; background-color:#DA4A38;"><div><a class="active" href="">menu2</a></div></li>
<li><div><a class="active" href="">menu3</a></div></li>
<li><div><a class="active" href="">menu4</a></div></li>
</ul>
</div>
I have a dropdown menu which works exactly as expected in Chrome.
The dropdown list is with position absolute, and the parent with position relative. However, it seems to render differently in Firefox. The dropped menu appears to be relative to the ul element rather than the li element
This dropdown is activated using javascript, adding a display:block on click
Any ideas why?
I did not use a table.
Fiddle
http://jsfiddle.net/eyJ8e/1/
HTML
<div id="menubar">
<div class="container">
<ul class="menu-container title" style="float:left;">
<li>NEW
</li>
<li class="dropdown"> <a class="click-dropdown" href="#">MEN</a><span class="caret"></span>
<ul class="dropdown-menu" style="display:block"> <li>Jeans</li>
<li>Pants</li>
<li>Shirts</li>
<li>Shorts</li>
<li>Tees</li>
</ul>
</li>
</ul>
</div>
</div>
CSS
body
{
width: 100%;
margin: 0px;
padding: 0px;
font-family: Calibri, Candara, Segoe, "Segoe UI", Optima, Arial, sans-serif;
font-size: 10pt;
/* background-color: #f0f0f0; */
}
.title{
/*font-family: Impact, Charcoal, sans-serif;*/
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
text-transform: uppercase;
font-family: SourceSans Pro Bold;
}
.container{
width:1024px;
margin:0 auto;
}
a, a:active, a:visited
{
color: #000000;
text-decoration: none;
outline: none;
}
a:hover
{
text-decoration: none;
}
#menubar {
width:100%;
min-width:1000px;
height:75px;
background-color:#000;
line-height: 75px;
color:white;
}
#menubar .brand{
display: block;
height:75px;
width: 120px;
margin-right:30px;
margin-top:3px;
float:left;
color:white!important;
}
#menubar .menu-container{
list-style:none;
margin:0px;
}
#menubar .menu-container li:first{
border-left: 1px solid grey;
}
#menubar .menu-container li{
position:relative;
display:inline;
padding:0px 15px;
font-size: 14px;
text-transform: uppercase;
border-right: 1px solid grey;
height:75px;
}
#menubar .menu-container > li.shopping-bag-wrapper:hover{
text-decoration: none;
}
#menubar .menu-container li.shopping-bag-wrapper{
border-right:none;
padding-right:0px;
}
#menubar .authentication-fb-form{
display:inline;
}
#menubar .menu-container li a{
color: white!important;
}
#menubar .menu-container li:last-child{
border:none;
}
#menubar .menu-container .dropdown ul.dropdown-menu > li:hover{
background-color:#555555;
}
#menubar .menu-container ul.dropdown-menu{
border:none;
position:absolute;
z-index:1000;
background-color:black;
display:none;
margin-top:-20px;
}
#menubar .menu-container .dropdown-menu li{
display:block;
min-width:150px;
max-width: 250px;
height:auto;
}
#menubar .menu-container .dropdown-menu a{
display:block;
line-height:25px;
padding: 5px 0px;
height:auto;
border: 2px solid white;
border-bottom:0px;
}
#menubar .menu-container .dropdown-menu a:last-child{
border: 2px solid white;
}
ul{
list-style: none;
margin:0px;
padding:0px;
}
.inline-block{
display: inline-block;
}
.pull-right{
float:right!important;
}
.caret{
display: inline-block;
width: 0;
height: 0;
margin-left: 2px;
vertical-align: middle;
border-top: 4px solid;
border-right: 4px solid transparent;
border-left: 4px solid transparent;
}
There are a couple of issues here. Firstly, you are nesting <li>'s within <a>'s which is invalid. You need to fix this:
<ul class="dropdown-menu">
<li>Jeans</li>
<li>Pants</li>
<li>Shirts</li>
<li>Shorts</li>
<li>Tees</li>
</ul>
secondly, you arent actually giving your nested <ul> a left position which FF seems to need:
#menubar .menu-container ul.dropdown-menu{
left: 0;
}
You will then also need to move your border from the <a> to the <li> to keep the styling that you had before making these changes.
DEMO
just put left:0 in #menubar
.menu-container ul.dropdown-menu{left:0}
refer http://jsfiddle.net/aashi/eyJ8e/8/
For a drop down menu you may check this demo link :
The html part:
<ul class="menubar">
<li>NEW</li>
<li>MENU
<ul class="dropmenu">
<li>JEANS</li>
<li>PANTS</li>
<li>SHIRTS</li>
<li>SHORTS</li>
<li>TEES</li>
</ul>
</li>
</ul>
the CSS part:
*{ margin:0; padding:0;}
ul.menubar{
margin:0 auto;
width:100%;
background:#000;
height:40px;
display:block;
}
ul.menubar li{
list-style-type:none;
display:inline-block;
float:left;
position:relative;
}
ul.menubar li a{
display:block;
text-decoration:none;
color:#fff;
padding:10px;
}
ul.menubar li ul.dropmenu{
position:absolute;
width:120px;
padding:10px 10px 10px 0;
display:none;
}
ul.menubar li:hover ul.dropmenu{
display:block;
top:30px;
}
ul.menubar li:hover ul.dropmenu li{
background:#222;
width:100%;
}
ul.menubar li:hover ul.dropmenu li a:hover{
background:#333;
}
Here is the JS fiddle:
http://jsfiddle.net/ameysawant/LPdqV/1/