I have the following html for my header.
<header id="header">
<img src="images/logo.png"/>
<div class="container">
<nav id="nav">
<ul>
<li>
Home
</li>
<li>
About Me
</li>
<li>
Pricing
</li>
<li>
Sessions
</li>
<li>
Sign Up
</li>
<li>
Contact
</li>
</ul>
</nav>
</div>
</header>
I have the following for my CSS:
img .header-basic{
height:30px;
}
#content {
margin: 5px;
margin-top:00px;
}
#logo {
height: 100px;
top: 0px;
position: absolute;
left: 75px;
}
#content img{
float:right;
}
/*Header*/
#header img {
width: 450px;
height: auto;
display:block;
margin: 0 auto;
}
#media only screen and (max-width:800px) {
#header img {
width: 100%;
height: auto;
display: block;
margin: 0 auto;
}
#nav ul {
text-align: center;
}
#nav ul li {
display: inline;
text-decoration: none;
margin-left: 15px;
margin-right: 15px;
text-align: center;
font-family: 'Verdana';
}
#nav ul li a {
text-decoration: none;
color: black;
font-size: 20px;
font-family: 'Verdana';
}
}
#nav ul {
text-align: center;
}
#nav ul li {
display: inline;
text-decoration: none;
margin-left: 20px;
margin-right: 20px;
text-align: center;
font-family: 'Verdana';
}
#nav ul li a {
text-decoration: none;
color: black;
font-size: 20px;
font-family: 'Verdana';
}
/*End Header*/
My media query activates for making the image smaller but the text stays the same. I want the margin to be decreased to keep all the navigation on one line. I am coding in Visual Studio and testing in Chrome 55.0.2883.87 m (64-bit).
you can just decrease the margin and the font-size to make them in one line like this :
img .header-basic{
height:30px;
}
#content {
margin: 5px;
margin-top:00px;
}
#logo {
height: 100px;
top: 0px;
position: absolute;
left: 75px;
}
#content img{
float:right;
}
/*Header*/
#header img {
width: 450px;
height: auto;
display:block;
margin: 0 auto;
}
#nav ul {
text-align: center;
}
#nav ul li {
display: inline;
text-decoration: none;
margin-left: 15px;
margin-right: 15px;
text-align: center;
font-family: 'Verdana';
}
#nav ul li a {
text-decoration: none;
color: black;
font-size: 20px;
font-family: 'Verdana';
}
#media only screen and (max-width:800px) {
#header img {
width: 100%;
height: auto;
display: block;
margin: 0 auto;
}
#nav ul {
text-align: center;
}
#nav ul li {
display: inline;
text-decoration: none;
margin-left: 5px;
margin-right: 5px;
text-align: center;
font-family: 'Verdana';
}
#nav ul li a {
text-decoration: none;
color: black;
font-size: 15px;
font-family: 'Verdana';
}
}
#media only screen and (max-width:468px) {
#nav ul li {
margin-left: 1px;
margin-right: 1px;
}
#nav ul li a {
font-size: 10px;
}
}
/*End Header*/
<header id="header">
<img src="images/logo.png"/>
<div class="container">
<nav id="nav">
<ul>
<li>
Home
</li>
<li>
About Me
</li>
<li>
Pricing
</li>
<li>
Sessions
</li>
<li>
Sign Up
</li>
<li>
Contact
</li>
</ul>
</nav>
</div>
</header>
Related
I am very new to programming and am working on a website as a project for a class. I am attempting to create a drop down menu, but I continually run into an issue where my links in the drop down sub-menu are not taking up the full width I would like. See the pic below.
https://i.stack.imgur.com/u6koe.png
I would like the link and thus the hovered white background to extend the full width of the sub-menu but I cannot figure out how to make it work.
Here is my HTML:
<header id="mainheader">
<nav>
<ul id="menu">
<li>About Me</li>
<li>Creativity
<ul class="submenu">
<li>Skiing</li>
<li>Island</li>
<li>Cooking</li>
</ul>
</li>
<li>Revisions</li>
</ul>
</nav>
</header>
Here is my CSS:
body {
margin-top: 0px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin-left: auto;
margin-right: auto;
background-color: aquamarine;
}
#mainheader {
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
background-color: #818181;
text-align: center;
}
#menu {
padding: 0;
margin: 0;
}
#menu li {
display: inline-block;
list-style: none;
padding-top: 10px;
padding-bottom: 10px;
position: relative;
}
#menu li a {
text-decoration: none;
font-weight: bold;
color: white;
padding: 10px 30px;
}
#menu li a:hover {
background-color: white;
color: black;
}
#menu li ul.submenu {
height: auto;
width: 133px;
background: #818181;
position: absolute;
display: none;
padding: 0;
margin-top: 10px;
}
#menu li:hover ul.submenu {
display: block;
}
#menu li ul.submenu li {
width: 133px;
}
#menu li ul.submenu li a {
text-decoration: none;
padding: 10px 0px;
}
Any assistance is appreciated.
Add display: inline-block; and width: 100%; to your #menu li ul.submenu li a css rule.
body {
margin-top: 0px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin-left: auto;
margin-right: auto;
background-color: aquamarine;
}
#mainheader {
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
background-color: #818181;
text-align: center;
}
#menu {
padding: 0;
margin: 0;
}
#menu li {
display: inline-block;
list-style: none;
padding-top: 10px;
padding-bottom: 10px;
position: relative;
}
#menu li a {
text-decoration: none;
font-weight: bold;
color: white;
padding: 10px 30px;
}
#menu li a:hover {
background-color: white;
color: black;
}
#menu li ul.submenu {
height: auto;
width: 133px;
background: #818181;
position: absolute;
display: none;
padding: 0;
margin-top: 10px;
}
#menu li:hover ul.submenu {
display: block;
}
#menu li ul.submenu li {
width: 133px;
}
#menu li ul.submenu li a {
text-decoration: none;
padding: 10px 0px;
display: inline-block;
width: 100%;
}
<header id="mainheader">
<nav>
<ul id="menu">
<li>About Me</li>
<li>Creativity
<ul class="submenu">
<li>Skiing</li>
<li>Island</li>
<li>Cooking</li>
</ul>
</li>
<li>Revisions</li>
</ul>
</nav>
</header>
I am struggling with trying to recreate this submenu in html/css. The submenu is bigger wider than the parent <li> which seems to be the main issue. I need the submenu to be larger than the parent <li> and centered on it. This is what I am trying to recreate:
Screenshot of current progress:
So you can see in my version, the width of the submenu <ul> is only as big as the parent <li>. I need the submenu to be larger than the parent <li> and centered on it.
.navbar {
width: 100%;
height:80px;
font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
color: #111111;
background-color: #F9F9F9;
margin: 0;
padding: 0;
position: relative;
}
.logo {
font-size: 1.8em;
float: left;
line-height:80px;
width: 35%;
margin: 0;
padding: 0;
}
.nav {
float: right;
line-height:80px;
width: 65%;
margin: 0;
padding: 0;
font-size:0.8em;
text-align: right;
position: relative;
}
.nav li {
display: inline-block;
width: 75px;
text-align: center;
}
.nav li a {
position: relative;
}
.nav li ul {
position: absolute;
width: inherit;
text-align: center;
margin: -20px auto 0;
}
.nav > li > ul {
display: block;
border: 1px solid #111111;
padding: 0;
text-align: center;
}
.nav li ul li {
display: block;
margin: 0;
padding: 0;
line-height: 1;
}
.flLeft {
float: left;
}
.flRight {
float: right;
}
.white {
color: #ffffff;
}
.darkOrange {
color: #BF3600;
}
.black {
color: #111111;
}
.orange {
color: #FF6200;
}
a:link, a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.nav li a:link, .nav li a:visited {
color: #111111;
}
.nav li a:hover {
text-decoration: none;
border-bottom: 4px solid #FF6200;
font-weight: bold;
}
<div class="navbar">
<div class="container">
<div class="logo">
<span class="black">YOUR</span><span class="orange">LOGO</span>
</div>
<ul class="nav">
<li>
TITLE 1
</li>
<li>
TITLE 2
<ul>
<li>SUBMENU 1</li>
<li>SUBMENU 2</li>
<li>SUBMENU 3</li>
</ul>
</li>
<li>
TITLE 3
</li>
<li>
TITLE 4
</li>
<li>
TITLE 5
</li>
<li>
TITLE 6
</li>
<li>
TITLE 7
</li>
</div>
</div>
And I've created a fiddle: https://jsfiddle.net/gsmzhptu/embedded/result/
Updated fiddle with wide submenu, but not centered below main li menu item: https://jsfiddle.net/gsmzhptu/1/embedded/result/
I increased the line height. Do you want something like this?
.nav li ul li {
line-height: 2;
}
Check this JSFiddle: https://jsfiddle.net/gsmzhptu/11/
Positioning Solution
margin: -20px; and padding: adjustable 20px;
margin-left right and padding- left right should be exact and opposite to each other.
.nav > li > ul{
margin:-20px;
padding: 20px;
}
.nav li ul li {
{
margin:10px 0;
}
.navbar {
width: 100%;
height: 80px;
font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
color: #111111;
background-color: #F9F9F9;
margin: 0;
padding: 0;
position: relative;
}
.logo {
font-size: 1.8em;
float: left;
line-height: 80px;
width: 35%;
margin: 0;
padding: 0;
}
.nav {
float: right;
line-height: 80px;
width: 65%;
margin: 0;
padding: 0;
font-size: 0.8em;
text-align: right;
position: relative;
}
.nav li {
display: inline-block;
width: 75px;
text-align: center;
}
.nav li a {
position: relative;
}
.nav li ul {
position: absolute;
width: inherit;
text-align: center;
}
.nav>li>ul {
display: block;
border: 1px solid #111111;
padding: 0;
text-align: center;
margin: -20px;
padding: 20px;
}
.nav li ul li {
display: block;
margin: 0;
padding: 0;
line-height: 1;
margin: 10px 0px;
}
.flLeft {
float: left;
}
.flRight {
float: right;
}
.white {
color: #ffffff;
}
.darkOrange {
color: #BF3600;
}
.black {
color: #111111;
}
.orange {
color: #FF6200;
}
a:link,
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.nav li a:link,
.nav li a:visited {
color: #111111;
}
.nav li a:hover {
text-decoration: none;
border-bottom: 4px solid #FF6200;
font-weight: bold;
<div class="navbar">
<div class="container">
<div class="logo">
<span class="black">YOUR</span><span class="orange">LOGO</span>
</div>
<ul class="nav">
<li>
TITLE 1
</li>
<li>
TITLE 2
<ul>
<li>SUBMENU 1</li>
<li>SUBMENU 2</li>
<li>SUBMENU 3</li>
</ul>
</li>
<li>
TITLE 3
</li>
<li>
TITLE 4
</li>
<li>
TITLE 5
</li>
<li>
TITLE 6
</li>
<li>
TITLE 7
</li>
</div>
</div>
How can i center the float element that you can see in this photo? I want to bring it from the left of the web page to the middle, but keeping it at the top of the page?
Here is the code of the HTML:
<html>
<head>
<title>Batch File Generator | Home</title>
</head>
<link href="style.css" rel="stylesheet" >
<ul>
<li><a>Home</a></li>
<li><a>Download</a>
<ul>
<li>32-bit version</li>
<li>64-bit version</li>
</ul>
</li>
<li><a>Discussion</a>
<ul>
<li><a>Community forums</li></a>
<li><a>Ask the developers</li></a>
</ul>
</li>
<li><a>News</a></li>
</ul>
</html>
And here is the code of the CSS:
body{
background: url("background.jpg") no-repeat;
background-size: cover;
font-family: Arial;
color: white;
}
ul{
margin: 0px;
padding: 0px;
list-style: none;
}
ul li {
float: left;
width: 200px;
height: 40px;
background-color: black;
opacity: .8;
line-height: 40px;
text-align: center;
font-size: 20px;
}
ul li a {
text-decoration: none;
color: white;
display: block;
}
ul li a:hover {
background-color: green;
}
ul li ul li {
display: none;
}
ul li:hover ul li {
display: block;
}
For HTML Code, use this:
<div class="wrapper">
<div class="middle-content">
<ul>
<li><a>Home</a></li>
<li><a>Download</a>
<ul>
<li>32-bit version</li>
<li>64-bit version</li>
</ul>
</li>
<li><a>Discussion</a>
<ul>
<li><a>Community forums</a></li>
<li><a>Ask the developers</a></li>
</ul>
</li>
<li><a>News</a></li>
</ul>
</div>
</div>
For css code:
html{
height: 100%;
}
body{
background: url("background.jpg") no-repeat;
background-size: cover;
font-family: Arial;
color: white;
height: 100%;
}
.wrapper{
display: table;
width: 100%;
height: 100%;
}
.middle-content{
display: table-cell;
vertical-align:middle;
width: 100%;
}
ul{
margin: 0px;
padding: 0px;
list-style: none;
}
ul li {
float: left;
width: 200px;
height: 40px;
background-color: black;
opacity: .8;
line-height: 40px;
text-align: center;
font-size: 20px;
}
ul li a {
text-decoration: none;
color: white;
display: block;
}
ul li a:hover {
background-color: green;
}
ul li ul li {
display: none;
}
ul li:hover ul li {
display: block;
}
Solution with flexbox.
* {
box-sizing: border-box;
}
html,
body,
ul {
padding: 0;
margin: 0;
}
nav {
width: 100%;
background-color: darkgray;
}
li {
list-style: none;
padding: 15px;
border: thin solid lightgray;
position: relative;
background-color: white;
}
li>a {
display: inline-block;
text-decoration: none;
}
.main-menu {
display: flex;
justify-content: center;
}
.sub-menu {
display: none;
position: absolute;
left: 0px;
width: 100%;
margin-top: 15px;
}
.main-menu li:hover {
background-color: lightgreen;
}
.sub-menu li:hover {
background-color: lightblue;
}
.main-menu li:hover>.sub-menu {
display: block;
}
<nav>
<ul class="main-menu">
<li><a>Home</a></li>
<li><a>Download</a>
<ul class="sub-menu">
<li>32-bit version</li>
<li>64-bit version</li>
</ul>
</li>
<li><a>Discussion</a>
<ul class="sub-menu">
<li>Community forums</li>
<li>Ask the developers</li>
</ul>
</li>
<li><a>News</a></li>
</ul>
</nav>
I have a navigation menu which is dropping down its list below a left floated logo in Mobile Responsive Mode. This is happening possibly due to the logo's float property. How can i make the dropdown appear just below the menu button. Click on menu atthis fiddle https://jsfiddle.net/AwesomeHat/rseuct2x/ to see.
HTML Code-
<div id="header">
<img src="http://www.operadevelopers.com/images/logo.png" class="logo" />
<div id="social">
<i class="fa fa-wikipedia-w" aria-hidden="true"></i>
<i class="fa fa-linkedin" aria-hidden="true"></i>
<i class="fa fa-google-plus" aria-hidden="true"></i>
<i class="fa fa-twitter" aria-hidden="true"></i>
<i class="fa fa-facebook" aria-hidden="true"></i>
</div>
<!--Navigation Bar-->
<nav>
<label for="show-menu" class="show-menu">Menu ☰</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu">
<li>Home</li>
<li>About us</li>
<li>Whats New
<ul class="hidden">
<li>Just Launched</li>
<li>Launching Soon</li>
<li>Completed Projects</li>
</ul>
</li>
<li>Referral</li>
<li>Buyers Section
<ul class="hidden">
<li>EMI Calculator</li>
<li>Apply For Loan</li>
<li>Make an Enquiry</li>
</ul>
</li>
<li>Careers</li>
<li>Contact</li>
</ul>
</nav>
</div>
CSS Code -
#header {
background: black;
width: 100%;
height: 210px;
min-height: 100%;
}
.logo {
float: left;
padding-left: 5%;
padding-top: 25px;
}
.icon-button {
color: white;
border: 0px;
display: inline-block;
font-size: 1.0rem;
line-height: 1.7rem;
margin: 1px;
text-align: center;
width: 1.7rem;
margin-top: 60px;
float: right;
overflow: hidden;
}
.facebook {
background-color: #3B5998;
}
.twitter {
background-color: #4099ff;
}
.google-plus {
background-color: #db5a3c;
}
.linkedin {
background-color: #007fb1;
}
.wikipedia {
background-color: white;
overflow: hidden;
color: black;
margin-right: 100px;
}
.icon-button:hover {
background-color: rgba(165,219,89,1);
transition: 1s;
transform: rotate(360deg);
}
nav ul {
list-style-type:none;
margin-top: 170px;
padding:0;
position: absolute;
width: 100%;
z-index: 20000;
}
nav ul li {
display:inline-block;
float: left;
width: 14.2857%; /* fallback for non-calc() browsers */
width: calc(100% / 7);
}
nav ul li a {
display:block;
min-width:140px;
height: 40px;
text-align: center;
line-height: 40px;
font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
color: #fff;
background: #161616;
text-decoration: none;
}
nav ul li:hover a {
color: rgb(165,219,89);
}
nav ul li:hover ul a {
color: #fff;
height: 40px;
line-height: 40px;
}
nav ul li:hover ul a:hover {
color: rgb(165,219,89);
}
nav ul li ul {
margin-top: 0px;
display: none;
}
nav ul li ul li {
display: block;
float: none;
width: 200px;
}
nav ul li ul li a {
width: auto;
min-width: 100px;
padding: 0 20px;
}
nav ul li a:hover + .hidden, .hidden:hover {
display: block;
}
.show-menu {
float: right;
width: 70px;
height: 25px;
margin-top: 90px;
margin-right: -100px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-decoration: none;
color: #fff;
background: blue;
text-align: center;
display: none;
}
input[type=checkbox]{
display: none;
}
input[type=checkbox]:checked ~ #menu{
display: block;
}
#media screen and (max-width : 760px){
.logo {
padding-left: 10%;
}
.icon-button {
font-size: 0.8rem;
line-height: 1.5rem;
width: 1.5rem;
margin-top: 60px;
}
.wikipedia {
margin-right: 7%;
}
nav ul {
position: relative;
margin-top: 0;
float: right;
display: none;
}
nav ul li, li a {
width: 90%;
}
nav ul li ul {
margin-top: 0px;
display: block;
}
nav ul li ul li {
width: 90%;
}
.show-menu {
display:block;
}
try below code, i think this can helpful for you.
#header {
background: black;
width: 100%;
height: 210px;
min-height: 100%;
}
.logo {
float: left;
padding-left: 5%;
padding-top: 25px;
}
.icon-button {
color: white;
border: 0px;
display: inline-block;
font-size: 1.0rem;
line-height: 1.7rem;
margin: 1px;
text-align: center;
width: 1.7rem;
margin-top: 60px;
float: right;
overflow: hidden;
}
.facebook {
background-color: #3B5998;
}
.twitter {
background-color: #4099ff;
}
.google-plus {
background-color: #db5a3c;
}
.linkedin {
background-color: #007fb1;
}
.wikipedia {
background-color: white;
overflow: hidden;
color: black;
margin-right: 100px;
}
.icon-button:hover {
background-color: rgba(165,219,89,1);
transition: 1s;
transform: rotate(360deg);
}
nav ul {
list-style-type:none;
margin-top: 170px;
padding:0;
position: absolute;
width: 75%;
z-index: 20000;
}
nav ul li {
display:inline-block;
float: left;
width: 14.2857%; /* fallback for non-calc() browsers */
width: calc(100% / 7);
}
nav ul li a {
display:block;
min-width:140px;
height: 40px;
text-align: center;
line-height: 40px;
font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
color: #fff;
background: #161616;
text-decoration: none;
}
nav ul li:hover a {
color: rgb(165,219,89);
}
nav ul li:hover ul a {
color: #fff;
height: 40px;
line-height: 40px;
}
nav ul li:hover ul a:hover {
color: rgb(165,219,89);
}
nav ul li ul {
margin-top: 0px;
display: none;
}
nav ul li ul li {
display: block;
float: none;
width: 200px;
}
nav ul li ul li a {
width: auto;
min-width: 100px;
padding: 0 20px;
}
nav ul li a:hover + .hidden, .hidden:hover {
display: block;
}
.show-menu {
float: right;
width: 70px;
height: 25px;
margin-top: 90px;
margin-right: -100px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-decoration: none;
color: #fff;
background: blue;
text-align: center;
display: none;
}
input[type=checkbox]{
display: none;
}
input[type=checkbox]:checked ~ #menu{
display: block;
}
#media screen and (max-width : 760px){
.logo {
padding-left: 10%;
}
.icon-button {
font-size: 0.8rem;
line-height: 1.5rem;
width: 1.5rem;
margin-top: 60px;
}
.wikipedia {
margin-right: 7%;
}
nav ul {
position: relative;
margin-top: 0;
float: right;
display: none;
}
nav ul li, li a {
width: 90%;
}
nav ul li ul {
margin-top: 0px;
display: block;
}
nav ul li ul li {
width: 90%;
}
.show-menu {
display:block;
}
nav ul li ul li {
width: 100%;
}
.hidden {
width: 100%;
}
nav ul li, li a {
width: 100%;
}
nav ul {
margin-right: 0;
margin-top: 60px;
}
nav ul li ul li a {
padding: 0 16px;
}
<div id="header">
<img src="http://www.operadevelopers.com/images/logo.png" class="logo" />
<div id="social">
<i class="fa fa-wikipedia-w" aria-hidden="true"></i>
<i class="fa fa-linkedin" aria-hidden="true"></i>
<i class="fa fa-google-plus" aria-hidden="true"></i>
<i class="fa fa-twitter" aria-hidden="true"></i>
<i class="fa fa-facebook" aria-hidden="true"></i>
</div>
<!--Navigation Bar-->
<nav>
<label for="show-menu" class="show-menu">Menu ☰</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu">
<li>Home</li>
<li>About us</li>
<li>Whats New
<ul class="hidden">
<li>Just Launched</li>
<li>Launching Soon</li>
<li>Completed Projects</li>
</ul>
</li>
<li>Referral</li>
<li>Buyers Section
<ul class="hidden">
<li>EMI Calculator</li>
<li>Apply For Loan</li>
<li>Make an Enquiry</li>
</ul>
</li>
<li>Careers</li>
<li>Contact</li>
</ul>
</nav>
</div>
I could only look fast over your Code, but i think your Menu Button is always at the same Position.
So you can add a margin-top tag to your css.
#menu {
margin-top: -37px;
}
At my Computer, this works fine. But you have to try it on mobile device.
You have set the nav ul li to be float: left;, so if you change that to float: right; like so:
#header {
background: black;
width: 100%;
height: 210px;
min-height: 100%;
}
.logo {
float: left;
padding-left: 5%;
padding-top: 25px;
}
.icon-button {
color: white;
border: 0px;
display: inline-block;
font-size: 1.0rem;
line-height: 1.7rem;
margin: 1px;
text-align: center;
width: 1.7rem;
margin-top: 60px;
float: right;
overflow: hidden;
}
.facebook {
background-color: #3B5998;
}
.twitter {
background-color: #4099ff;
}
.google-plus {
background-color: #db5a3c;
}
.linkedin {
background-color: #007fb1;
}
.wikipedia {
background-color: white;
overflow: hidden;
color: black;
margin-right: 100px;
}
.icon-button:hover {
background-color: rgba(165,219,89,1);
transition: 1s;
transform: rotate(360deg);
}
nav ul {
list-style-type:none;
margin-top: 170px;
padding:0;
position: absolute;
width: 100%;
z-index: 20000;
}
nav ul li {
display:inline-block;
float: right;
width: 14.2857%; /* fallback for non-calc() browsers */
width: calc(100% / 7);
}
nav ul li a {
display:block;
min-width:140px;
height: 40px;
text-align: center;
line-height: 40px;
font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
color: #fff;
background: #161616;
text-decoration: none;
}
nav ul li:hover a {
color: rgb(165,219,89);
}
nav ul li:hover ul a {
color: #fff;
height: 40px;
line-height: 40px;
}
nav ul li:hover ul a:hover {
color: rgb(165,219,89);
}
nav ul li ul {
margin-top: 0px;
display: none;
}
nav ul li ul li {
display: block;
float: none;
width: 200px;
}
nav ul li ul li a {
width: auto;
min-width: 100px;
padding: 0 20px;
}
nav ul li a:hover + .hidden, .hidden:hover {
display: block;
}
.show-menu {
float: right;
width: 70px;
height: 25px;
margin-top: 90px;
margin-right: -100px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-decoration: none;
color: #fff;
background: blue;
text-align: center;
display: none;
}
input[type=checkbox]{
display: none;
}
input[type=checkbox]:checked ~ #menu{
display: block;
}
#media screen and (max-width : 760px){
.logo {
padding-left: 10%;
}
.icon-button {
font-size: 0.8rem;
line-height: 1.5rem;
width: 1.5rem;
margin-top: 60px;
}
.wikipedia {
margin-right: 7%;
}
nav ul {
position: relative;
margin-top: 0;
float: right;
display: none;
}
nav ul li, li a {
width: 90%;
}
nav ul li ul {
margin-top: 0px;
display: block;
}
nav ul li ul li {
width: 90%;
}
.show-menu {
display:block;
}
<div id="header">
<img src="http://www.operadevelopers.com/images/logo.png" class="logo" />
<div id="social">
<i class="fa fa-wikipedia-w" aria-hidden="true"></i>
<i class="fa fa-linkedin" aria-hidden="true"></i>
<i class="fa fa-google-plus" aria-hidden="true"></i>
<i class="fa fa-twitter" aria-hidden="true"></i>
<i class="fa fa-facebook" aria-hidden="true"></i>
</div>
<!--Navigation Bar-->
<nav>
<label for="show-menu" class="show-menu">Menu ☰</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu">
<li>Home</li>
<li>About us</li>
<li>Whats New
<ul class="hidden">
<li>Just Launched</li>
<li>Launching Soon</li>
<li>Completed Projects</li>
</ul>
</li>
<li>Referral</li>
<li>Buyers Section
<ul class="hidden">
<li>EMI Calculator</li>
<li>Apply For Loan</li>
<li>Make an Enquiry</li>
</ul>
</li>
<li>Careers</li>
<li>Contact</li>
</ul>
</nav>
</div>
body {
margin: auto;
max-width: 98%;
overflow-y: scroll;
}
div {
border-radius: 5px;
}
span {
font-weight:bold;
}
#header {
position: absolute;
z-index: 1;
background-color: orange;
height: 70px;
width: 98%;
margin-top: -10px;
margin-bottom: 10px;
}
#name {
float:left;
margin-left: 400px;
margin-top: 10px;
padding-top: 1px;
font-size: 20px;
font-family: Verdana, sans-serif;
color: brown;
}
#contact {
position: absolute;
margin-left: 250px;
margin-top: 30px;
padding-top: -1px;
font-family: Verdana, sans-serif;
color: brown;
}
#email {
position: absolute;
margin-left: 360px;
margin-top: 45px;
padding-top: 1px;
font-size: 16px;
font-family: Verdana, sans-serif;
color: brown;
}
a:hover {
font-weight: bold;
}
a,visited {
color: black;
}
#nav {
position: relative;
background-color: brown;
float: left;
width: 11%;
height: 820px;
margin-top: 70px;
margin-bottom: 10px;
}
#nav_wrapper {
width: 900px;
margin: 0px auto;
text-align: left;
}
#nav ul {
list-style-type: none;
margin: 0px;
padding: 0px;
position: relative;
}
#nav ul li {
display: block;
}
#nav ul li:hover {
background-color: #333;
width: 219px;
}
#nav ul a,visited {
color: #ccc;
display: block;
padding: 15px;
text-decoration: none;
}
#nav ul a:hover {
color: #099;
text-decoration: none;
padding: auto;
}
#nav ul li:hover ul {
display: block;
width: 219px;
}
#nav ul ul {
display: none;
position: absolute;
}
#nav ul ul li {
display: block;
padding: 25.5px;
background-color: #222;
}
#nav ul ul li:hover {
color: #099;
width: 168px;
}
#nav ul ul li,visited {
color: #ccc;
}
ul .sub_navi {
display: none;
}
li:hover .sub_navi {
background: #999;
border: #fff solid;
border-width: 1px;
display: block;
position: absolute;
left: 220px;
top: 4px;
}
.right {
position: static;
background-color: linen;
float: right;
width: 88%;
height: 820px;
margin-top: 70px;
margin-bottom: 10px;
padding: 5px;
}
h4 {
margin-left: 5px;
margin-bottom: 15px;
font-family: Verdana, sans-serif;
text-decoration: underline;
}
.right p {
margin-left: 5px;
margin-right: 5px;
margin-top: -10px;
font-family: Garamond, serif;
color: #000000;
}
#company {
font-family: Garamond, serif;
}
#position {
font-style: italic
}
li {
list-style-type: square;
}
#footer {
height: 40px;
width: 100%;
background-color: orange;
position: relative;
clear: both;
}
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css"/>
<title></title>
</head>
<body>
<div id=header>
<p id="name">Henry jones</p>
</div>
<div id="nav">
<div id="nav_wrapper">
<ul>
<li>Home</li>
<li>About Me
<ul>
<li>Board Games
<ul class="sub_navi">
<li>Cosmic Encounter</li>
<li>Agricola</li>
<li>Trajan</li>
</ul>
</li>
<li>League of Legends</li>
<li>Sports</li>
</ul>
</li>
<li>Travels
<ul>
<li>Paris</li>
<li>Turks and Caicos</li>
<li>Puerto Rico</li>
<li>Chicago</li>
</ul>
</li>
</li>
<li>Resume</li>
<li>Contact
<ul>
<li>Phone</li>
<li>Email</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="right">
<h4>Welcome</h4>
<p><img src="https://pbs.twimg.com/media/CAY3PIpXEAAkO75.png"></a>
</p>
I have created the drop down menu but I am having some trouble. Please help me with this html. The problem is when I hover my cursor next to the navi bar I, the navigation bar keeps "blinking". I would like some assistant on how to code this more efficiently. Also, where do i put display:none to make the board game sub navi disappear when highlight something else. Thank you.
Try to use width: 100%; for #nav_wrapper. This will solve the problem.
I finally fixed it!
nav ul li {display: block;}
changed to
nav ul li {Visibility: hidden;}
and
nav ul li:hover ul {display: block;width: 219px;}
changed to
nav ul li:hover > ul {Visibility: visible;width: 219px;}