Child list disappears when hovered over it - css

I have a Horizontal Menu. When the mouse is hovered over the child elements it disappears. The child elements cannot be clicked. I would like the child elements to stay when the mouse is hovered over it.
.header {
color: #FFFFFF;
height: 60px;
width: 100%;
margin: auto;
}
.header_logo {
width: 40%;
height: 100%;
float: left;
}
#logo {
height: 100%;
top: 0;
left: 0;
width: 50%;
}
.header_title {
width: 60%;
float: left;
}
#titles {
position: absolute;
top: 20px;
font-family: "Times New Roman", Times, serif, Georgia;
font-size: 97%;
color: #B8B8B8;
}
ul {
list-style-type: none;
}
li {
display: inline-block;
}
a {
text-decoration: none;
color: inherit;
padding: 21px 10px;
}
li a:hover {
background-color: #666699;
}
ul li ul {
display: none;
}
ul li:hover ul {
display: block;
position: absolute;
width: 100%;
top: 70px;
left: 0;
white-space: nowrap;
}
* {
border: 0;
margin: 0;
padding: 0;
}
.content {
height: 800px;
margin: auto;
background-color: #C0C0C0;
}
.footer {
margin: auto;
background-color: #000000;
}
<div class="header">
<div class="header_logo">
<img id="logo" src="civic-logo.jpg">
</div>
<div class="header_title">
<div id="titles">
<ul>
<li>PRODUCTS
<ul>
<li>CEMENT</li>
<li>STEEL</li>
<li>BRICKS</li>
<li>SAND</li>
</ul>
</li>
<li>CONTACT US </li>
</ul>
</div>
</div>
</div>
<div class="content">
</div>
<div class="footer">
</div>

It's because you have positioned your submenu absolutely, and it's too far away from your parent li, so your mouse is leaving the parent menu before it reaches the submenu. I've added borders to show you.
.header {
color: #FFFFFF;
height: 60px;
width: 100%;
margin: auto;
}
.header_logo {
width: 40%;
height: 100%;
float: left;
}
#logo {
height: 100%;
top: 0;
left: 0;
width: 50%;
}
.header_title {
width: 60%;
float: left;
}
#titles {
position: absolute;
top: 20px;
font-family: "Times New Roman", Times, serif, Georgia;
font-size: 97%;
color: #B8B8B8;
}
ul {
list-style-type: none;
}
li {
display: inline-block;
border: 1px solid blue;
}
a {
text-decoration: none;
color: inherit;
padding: 21px 10px;
}
li a:hover {
background-color: #666699;
}
ul li ul {
display: none;
}
ul li:hover ul {
display: block;
position: absolute;
width: 100%;
top: 70px;
left: 0;
white-space: nowrap;
}
* {
border: 0;
margin: 0;
padding: 0;
}
.content {
height: 800px;
margin: auto;
background-color: #C0C0C0;
}
.footer {
margin: auto;
background-color: #000000;
}
<div class="header">
<div class="header_logo">
<img id="logo" src="civic-logo.jpg">
</div>
<div class="header_title">
<div id="titles">
<ul>
<li>PRODUCTS
<ul>
<li>CEMENT</li>
<li>STEEL</li>
<li>BRICKS</li>
<li>SAND</li>
</ul>
</li>
<li>CONTACT US </li>
</ul>
</div>
</div>
</div>
<div class="content">
</div>
<div class="footer">
</div>
You have padding, but it's on your a element, and needs to be on your li element, instead. Either add padding-top to your submenu li elements or adjust their top position so that they're directly underneath (aka "touching") the parent element.
Here is the code with the menu moved to top: 40px and the padding added to the submenu li elements:
.header {
color: #FFFFFF;
height: 60px;
width: 100%;
margin: auto;
}
.header_logo {
width: 40%;
height: 100%;
float: left;
}
#logo {
height: 100%;
top: 0;
left: 0;
width: 50%;
}
.header_title {
width: 60%;
float: left;
}
#titles {
position: absolute;
top: 20px;
font-family: "Times New Roman", Times, serif, Georgia;
font-size: 97%;
color: #B8B8B8;
}
ul {
list-style-type: none;
}
li {
display: inline-block;
}
a {
text-decoration: none;
color: inherit;
padding: 21px 10px;
}
li ul li {
padding: 21px 10px;
}
li a:hover {
background-color: #666699;
}
ul li ul {
display: none;
}
ul li:hover ul {
display: block;
position: absolute;
width: 100%;
top: 40px;
left: 0;
white-space: nowrap;
}
* {
border: 0;
margin: 0;
padding: 0;
}
.content {
height: 800px;
margin: auto;
background-color: #C0C0C0;
}
.footer {
margin: auto;
background-color: #000000;
}
<div class="header">
<div class="header_logo">
<img id="logo" src="civic-logo.jpg">
</div>
<div class="header_title">
<div id="titles">
<ul>
<li>PRODUCTS
<ul>
<li>CEMENT</li>
<li>STEEL</li>
<li>BRICKS</li>
<li>SAND</li>
</ul>
</li>
<li>CONTACT US </li>
</ul>
</div>
</div>
</div>
<div class="content">
</div>
<div class="footer">
</div>

Related

why doesn't my menu float to right side and items are displayed itselfs uncurrect?

Sorry for my English!
My menu is displayed incorrect! The problem: It doesn't located on full container! How fix it?
The code is here:
<header id="header">
<div class="center">
SITE NAME
<nav>
<ul>
<li class="active">HOME</li>
<li>ABOUT</li>
<li>SERVICES</li>
<li>PROJECT</li>
<li>BLOG</li>
<li>CONTACT</li>
</ul>
</nav>
<div class="clear"></div>
</div>
</header>
<style>
/*HEADER*/
/*HEADER*/
header{
padding: 20px 0;
/* height: 118px; */
position: fixed;
background: white;
width: 100%;
z-index:300;
}
header .logo{
float: left;
width: 20%;
color: #637f83;
font-size: 2em;
font-weight: bold;
margin: 0;
}
header nav ul {
/* position: absolute;
right: 0;
width: 70%; */
}
header nav{
float: left;
margin-left:50px;
/* width: 50%; */
line-height: 46px;
height: 50px;
}
header nav ul li{
float:left;
padding:0 0 0 1%;
}
header nav ul{
float:right;
}
header nav ul li a{
color:#637f83;
display:block;
float: left;
text-align: center;
padding: 0px 16px;
text-decoration: none;
font-size: 17px;
}
</style>
Thank you!
header {
padding: 20px 0;
/* height: 118px; */
position: fixed;
background: white;
width: 100%;
z-index: 300;
}
header .logo {
float: left;
width: 20%;
color: #637f83;
font-size: 2em;
font-weight: bold;
margin: 0;
}
header nav ul {
/* position: absolute;
right: 0;
width: 70%; */
}
header nav {
float: right;
width: 79%;
}
header nav ul li {
float: left;
padding: 0 0 0 1%;
}
header nav ul {
list-style: none
}
header nav ul li a {
color: #637f83;
display: block;
text-align: center;
padding: 0px 16px;
text-decoration: none;
font-size: 17px;
}
.clear {
clear: both
}
<header id="header">
<div class="center">
SITE NAME
<nav>
<ul>
<li class="active">HOME</li>
<li>ABOUT</li>
<li>SERVICES</li>
<li>PROJECT</li>
<li>BLOG</li>
<li>CONTACT</li>
</ul>
</nav>
<div class="clear"></div>
</div>
</header>
jsfiddler https://jsfiddle.net/3fw0ynLy/

Remove small gap between nav and header

My nav bar (which is at the top of the page) and header (below nav, which has a large image and a text on top of it), have a very small gap between them that I want to remove. I've visited a number of posts on similar problems, and tried their solutions, but can't seem to work for me, including: display: block; margin: 0; e.t.c.
I guess it has something to do with a style I have applied on either the header's content or the nav's content.
body {
margin: 0px;
padding: 0px;
background-color: #f2f2f2;
}
html {
margin: 0px;
padding: 0px;
}
#logo {
height: 50px;
width: auto;
float: left;
}
nav ul {
list-style-type: none;
overflow: hidden;
margin: 0;
padding: 0;
background-color: #1a1a1a;
text-align: center;
border: 1px solid #e7e7e7;
display: inline-block;
width: 100%;
}
nav li {
display: inline-block;
}
nav a {
display: inline-block;
padding: 16px 15px;
text-decoration: none;
font-family: arial;
font-weight: bold;
color: white;
}
nav a:hover {
background-color: orange;
color: white;
}
nav {
margin-bottom: 0;
}
header {
margin-top: 0;
margin-bottom: 10px;
width: 100%;
font-family: arial;
font-size: 18px;
color: orange;
}
h1 {
position: absolute;
top: 150px;
width: 100%;
z-index: 1;
text-align: center;
}
#bannerImage {
width: 100%;
height: auto;
position: relative;
z-index: 0;
}
<nav>
<ul>
<img id="logo" src="https://67.media.tumblr.com/f607af5bc60d1b2837add83c70a2aa45/tumblr_inline_mrwv19q8fE1qz4rgp.gif"/>
<li>Game 2</li><li>Game 3</li>
</ul>
</nav>
<header>
<img id="bannerImage" src="http://static2.hypable.com/wp-content/uploads/2014/09/Hogwarts-lake.png"/>
<h1>Games</h1>
</header>
Just define the height of nav
body {
margin: 0px;
padding: 0px;
background-color: #f2f2f2;
}
html {
margin: 0px;
padding: 0px;
}
#logo {
height: 50px;
width: auto;
float: left;
}
nav ul {
list-style-type: none;
overflow: hidden!important;
margin: 0;
padding: 0;
background-color: #1a1a1a;
text-align: center;
border: 1px solid #e7e7e7;
display: inline-block;
width: 100%;
}
nav li {
display: inline-block;
}
nav a {
display: inline-block;
padding: 16px 15px;
text-decoration: none;
font-family: arial;
font-weight: bold;
color: white;
}
nav a:hover {
background-color: orange;
color: white;
}
nav {
margin-bottom: 0;
height: 51px;
}
header {
margin-top: 0;
margin-bottom: 10px;
width: 100%;
font-family: arial;
font-size: 18px;
color: orange;
}
h1 {
position: absolute;
top: 150px;
width: 100%;
z-index: 1;
text-align: center;
}
#bannerImage {
width: 100%;
height: auto;
position: relative;
z-index: 0;
}
<nav>
<ul>
<img id="logo" src="https://67.media.tumblr.com/f607af5bc60d1b2837add83c70a2aa45/tumblr_inline_mrwv19q8fE1qz4rgp.gif"/>
<li>Game 2</li><li>Game 3</li>
</ul>
</nav>
<header>
<img id="bannerImage" src="http://static2.hypable.com/wp-content/uploads/2014/09/Hogwarts-lake.png"/>
<h1>Games</h1>
</header>
The problem is caused by your ul having overflow:hidden so just remove it.
Added box-sizing:border-box to avoid horizontal scrollbar
UPDATE
I noticed that you have an img as child of ul which makes that invalid HTML.
So I tweaked your code to make it valid.
*,
*::before,
*::after {
box-sizing: border-box
}
body,
html {
margin: 0;
padding: 0;
background-color: #f2f2f2;
}
#logo {
height: 50px;
width: auto;
display: inline-block;
vertical-align:top
}
nav {
margin-bottom: 0;
background-color: #1a1a1a;
border: 1px solid #e7e7e7;
}
nav ul {
list-style-type: none;
width: calc(100% - 60px);
margin:0;
padding: 0;
text-align: center;
display: inline-block;
vertical-align: top;
}
nav li {
display: inline-block;
}
nav a {
display: inline-block;
padding: 16px 15px;
text-decoration: none;
font-family: arial;
font-weight: bold;
color: white;
}
nav a:hover {
background-color: orange;
color: white;
}
header {
margin-top: 0;
margin-bottom: 10px;
width: 100%;
font-family: arial;
font-size: 18px;
color: orange;
}
h1 {
position: absolute;
top: 150px;
width: 100%;
z-index: 1;
text-align: center;
}
#bannerImage {
width: 100%;
height: auto;
position: relative;
z-index: 0;
}
<nav>
<img id="logo" src="https://67.media.tumblr.com/f607af5bc60d1b2837add83c70a2aa45/tumblr_inline_mrwv19q8fE1qz4rgp.gif" />
<ul>
<li>Game 1
</li>
<li>Game 2
</li>
<li>Game 3
</li>
</ul>
</nav>
<header>
<img id="bannerImage" src="http://static2.hypable.com/wp-content/uploads/2014/09/Hogwarts-lake.png" />
<h1>Games</h1>
</header>
Try setting the height of the nav:
nav {
height: 50px;
}
Tried it out and works even without the margin set to 0.

Why doesn't menu on drop down appear over content?

I've got a drop down menu that won't appear over the rest of the content. I've set the position to absolute and the z-index to 99 and no luck. Any ideas how to get it to lay on top of the rest of the site?
<body>
<header>
<div class="container">
<h1 class="logo">Relaxr</h1>
<nav>
</span>
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
<li>Blog</li>
</ul>
</nav>
</div>
</header>
<section id="main">
<div class="container">
nav {
position: relative;
}
nav ul {
display: none;
}
header {
margin-left: -20px;
margin-right: -20px;
}
body {
margin-left: 20px;
margin-right: 20px;
}
.container {
width: 100%;
margin: 0;
}
#main {
margin-top: 10px;
}
header nav ul li {
display: block;
margin-right: 20px;
margin: 0 20px 0 0;
}
.hamburger {
margin-top: 5px;
margin-right: 80px;
margin-bottom: 20px;
float:right;
position: relative;
display: inline-block;
width: 1.5em;
height: 0.74em;
border-top: 0.2em solid #fff;
border-bottom: 0.2em solid #fff;
}
.hamburger:before {
content: "";
position: absolute;
top: 0.9em;
left: 0px;
width: 100%;
border-top: 0.2em solid #fff;
}
nav ul {
position: absolute;
left: 0; top: 100%;
width: 100%;
background-color: black;
z-index: 99;
Codepen:
http://codepen.io/kiddigit/pen/wWvPJm
In your #media query change
nav {
position: relative;
}
to
nav {
position: absolute;
}
This will keep your menu on top.
I think You should use something like this to work
$(".hamburger").click(function(e){
$("nav > ul").toggle();
});
there is only one difference I've added a closing bracket in
$("nav > ul").toggle();

A child div inside of a parent div creates white space for the parent div

I dont understand whats happening, a parent div is being affected by the margins I want added to a child div. It is causing the parent div to shift down instead of staying in place and creating whitespace. my error is in the div with id "center".
* {
padding: 0;
margin: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
background-color: #57FFA6;
color: #221F51;
font-size: 62.5%;
font-family: arial, sans-serif;
}
#header {
background-color: white;
display: block;
height: 80px;
position: relative;
}
#logo {
display: block;
float: left;
margin-left: 115px;
margin-top: 18px;
padding: 0 auto;
position: relative;
}
#navigationBar {
display: block;
float: right;
margin-right: 115px;
margin-top: 27px;
padding: 0 auto;
position: relative;
}
#navigationBar ul li {
display: inline-block;
}
#navigationBar ul li a {
color: black;
font-family: arial, sans-serif;
font-size: 1.5em;
text-decoration: none;
padding: 5px;
position: relative;
}
#navigationBar ul li a:hover {
color: gray;
}
#center {
background-color: white;
display: block;
font-size: 1.6em;
margin: 0 auto;
padding: 0 auto;
position: relative;
width: 990px;
}
#articleOne {
display: block;
height: 200px;
position: relative;
}
#articleOneTitle {
display: block;
margin: 50px;
position: relative;
}
<div id="header">
<div id="logo">
<img src="C:/Workspace/MyWeblogicWorkspace/Purify/WebContent/Images/logo.png" alt="logo" height="42" width="115">
</div>
<div id="navigationBar">
<ul id="navigationBarList">
<li>Home
</li><b> ·</b>
<li>About
</li><b> ·</b>
<li>Schedule
</li><b> ·</b>
<li>Contact
</li>
</ul>
</div>
<!-- end of navigationBar -->
</div>
<!-- end of header -->
<div id="center">
<div id="articleOne">
<p id="articleOneTitle">In-Home Repair</p>
</div>
<!-- end of articleOne -->
</div>
<!-- end of center -->
<div id="footer">
</div>
<!-- end of footer -->
Add overflow: auto; to #center - strange, but it does the trick...
* {
padding: 0;
margin: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
background-color: #57FFA6;
color: #221F51;
font-size: 62.5%;
font-family: arial, sans-serif;
}
#header {
background-color: white;
display: block;
height: 80px;
position: relative;
}
#logo {
display: block;
float: left;
margin-left: 115px;
margin-top: 18px;
padding: 0 auto;
position: relative;
}
#navigationBar {
display: block;
float: right;
margin-right: 115px;
margin-top: 27px;
padding: 0 auto;
position: relative;
}
#navigationBar ul li {
display: inline-block;
}
#navigationBar ul li a {
color: black;
font-family: arial, sans-serif;
font-size: 1.5em;
text-decoration: none;
padding: 5px;
position: relative;
}
#navigationBar ul li a:hover {
color: gray;
}
#center {
background-color: white;
display: block;
font-size: 1.6em;
margin: 0 auto;
padding: 0 auto;
position: relative;
width: 990px;
overflow: auto;
}
#articleOne {
display: block;
height: 200px;
position: relative;
}
#articleOneTitle {
display: block;
margin: 50px;
position: relative;
}
<div id="header">
<div id="logo">
<img src="C:/Workspace/MyWeblogicWorkspace/Purify/WebContent/Images/logo.png" alt="logo" height="42" width="115">
</div>
<div id="navigationBar">
<ul id="navigationBarList">
<li>Home
</li><b> ·</b>
<li>About
</li><b> ·</b>
<li>Schedule
</li><b> ·</b>
<li>Contact
</li>
</ul>
</div>
<!-- end of navigationBar -->
</div>
<!-- end of header -->
<div id="center">
<div id="articleOne">
<p id="articleOneTitle">In-Home Repair</p>
</div>
<!-- end of articleOne -->
</div>
<!-- end of center -->
<div id="footer">
</div>
<!-- end of footer -->

How Can I Center One <li> in a <ul>

I have a top menu made by a list. All <li>s centers depending on the text though I want to center one the <li>s and then the rest of the <li>s should center on both sides. I want to center the image.
The top menu looks like this:
<div id="topMenu">
<ul>
<li>Forside</li>
<li>Kampe</li>
<li>Truppen</li>
<li><img id="logoMenu" src="images/logo.png"></li>
<li>Galleri</li>
<li>Statistik</li>
<li>Om Klubben</li>
</ul>
</div>
Then I have some CSS:
#topMenu {
background: #51a047;
width: 100%;
height: 50px;
line-height: 25px;
margin: 0 auto;
}
#topMenu ul {
list-style-type: none;
margin: 0;
padding: 10px;
text-align: center;
}
#topMenu li {
display: inline;
padding: 0 20px;
text-transform: uppercase;
}
#logoMenu {
background-image: url("images/logo.png");
width: 80px;
}
#topMenu img {
vertical-align: text-top;
}
Here's a jsFiddle
Personally I wouldn't have the logo as an element in the navigation. Semantically it doesn't make sense and its difficult to style. If you divide the menu items in to two ULs you can do the following:
HTML
<div id="topMenu">
<ul id="menu-left">
<li>AAA</li>
<li>BBB</li>
<li>CCC</li>
</ul>
<img src="URL" />
<ul id="menu-right">
<li>DDD</li>
<li>EEE</li>
<li>FFF</li>
</ul>
</div>
CSS
#topMenu {
background: #51a047;
width: 100%;
height: 50px;
line-height: 25px;
margin: 0 auto;
position: relative;
}
#topMenu ul {
list-style-type: none;
text-align: center;
margin: 0;
padding: 10px;
box-sizing: border-box; /* percentage width + padding */
width: 45%;
position: absolute;
top: 0;
}
#topMenu #menu-left {
left: 0;
}
#topMenu #menu-right {
right: 0;
}
#topMenu li {
display: inline;
padding: 0 20px;
text-transform: uppercase;
}
#topMenu a {
color: white;
text-decoration: none;
}
#logoMenu {
display: block;
width: 10%;
margin: 0 auto; /*center*/
}
#topMenu img {
margin: 0 auto;
display: block;
max-height: 100%;
max-width: 100%;
}
https://jsfiddle.net/vvu5k79r/2/

Resources