Drop Down Menu is Overlapping my Nav Bar - html

I'm building a site for a client and I'm having trouble getting the drop down menu to appear clear below the navbar - instead it is overlapping the navbar, and if I increase the top margin of the drop down menu to push it below the navbar there is a gap between the drop down and the parent list item where the hover property to make it appear does not take affect.
I've created a fiddle of the navbar here - http://jsfiddle.net/s4dpby4v/1/
And you can view the live version here - http://japesfawcett.com/ps/index.html
HTML:
<div class="header">
<div class="logo">
<h1>PAM SHAW INTERIORS</h1>
</div>
<nav>
<ul>
<li>ABOUT</li>
<li class="has-drop">
WORK +
<ul class="drop-down">
<li style="padding-bottom: 0;">COMMERCIAL</li>
<li style="padding-right: 80px; padding-bottom: 0;">RESIDENTIAL</li>
</ul>
</li>
<li>CONTACT</li>
</ul>
</nav>
</div>
CSS:
.header {
width: 100%;
background-color: #fff;
margin: 0 auto;
height: 75px;
z-index: 9999;
}
.logo h1 {
float: left;
font-size: 20px;
letter-spacing: 4px;
width: 25%;
padding-top: 10px;
margin-top: 18px;
margin-left: 75px;
font-weight: 300;
}
.logo a {
text-decoration: none;
color: #000;
}
nav {
font-family: 'Lato', sans-serif;
width: 60%;
font-size: 14px;
font-weight: 300;
text-align: right;
letter-spacing: 4px;
float: right;
margin-top: 19px;
margin-right: 75px;
}
nav ul {
float: right;
list-style: none;
padding-top: -5px;
}
nav li {
padding-left: 15px;
padding-right: 10px;
padding-bottom: 15px;
display: inline-block;
}
nav ul li ul.drop-down {
width: 100%;
background: #fff;
display: none;
position: absolute;
z-index: 999;
padding: 5px 0 5px 0;
margin: 15px 0 0 0;
left: 0;
line-height: 2.5;
clear: both;
border-top: 1px solid #F1F1F1;
}
nav li:hover ul.drop-down {
display: block;
}
nav ul li ul.dropdown li {
display: block;
padding: 0;
margin: 0;
}
nav li a {
text-decoration: none;
color: #000;
display: inline-block;
}
nav li a:hover {
text-decoration: none;
color: #CCC;
-webkit-transition: all 800ms ease;
-moz-transition: all 800ms ease;
-ms-transition: all 800ms ease;
-o-transition: all 800ms ease;
transition: all 800ms ease;
}
Any guidance or help would be greatly appreciated!

.has-drop {position: relative;}
nav ul li ul.drop-down {width: auto;}
nav li li {width: 100%; text-align: center; box-sizing: border-box;}
Will clean up you drop down, you just need to remove the inline styles that you have on here to fix up the list styles.:
<li style="padding-bottom: 0;">COMMERCIAL</li>
<li style="padding-right: 80px; padding-bottom: 0;">RESIDENTIAL</li>
Here is my fiddle: http://jsfiddle.net/s4dpby4v/6/

You can check with this css
.has-drop {
padding-bottom: 30px;
}
nav ul li ul.drop-down
{
margin: 27px 0 0;
}

Related

Using float to place an element in the right side with CSS

I'm trying to do a nav bar with a contact button stuck to the right of the page. I want contact to be aligned with the rest of the elements of the nav bar, however when I add float: right; it just disaligns my nav bar and it doesn't move contact to the right.
Here you can see my code: http://jsfiddle.net/LG2vR/19/
Can someone please tell me the proper way to accomplish this please?
Thanks!
Am not sure if this is what you need exactly, see the updated fiddle
http://jsfiddle.net/ov74xcyg/1/
Basically, i have used position absolute to move your last child of the navigation to the right side and increased width of the navigation till the end of the header.
nav {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100px;
padding: 10px 100px;
z-index: 500;
box-sizing: content-box;
transition: .3s;
background: red;
}
nav.white {
background: white;
height: 35px;
padding: 10px 100px;
transition: .5s;
}
nav ul {
list-style: none;
float: left;
margin: 0;
padding: 0;
display: flex;
width: 90%;
position: relative;
}
nav ul li {
list-style: none;
}
nav ul li:last-child {
display: inline-block;
right: 5%;
position: absolute;
top: 0;
}
nav ul li a {
line-height: 80px;
color: #FFFFFF;
margin: 12px 30px;
text-decoration: none;
text-transform: capitalize;
transition: .5s;
padding: 10px 5px;
font-size: 16px;
}
nav ul li a:hover {
background-color: rgba(255,255,255,0.2);
}
nav.white ul li a {
color: #000;
line-height: 40px;
transition: .5s;
}
nav ul li a:focus {
outline: none;
}
<div class="wrapper">
<nav>
<ul>
<li>LOGO</li>
<li>Home</li>
<li>Page 1</li>
<li>Page 2</li>
<li><a class="contact" href="#">Contact</a></li>
</ul>
</nav>
Just add:
nav ul li a {
float: left;
}
right before:
nav ul li a.contact {
float: right;
}
or use flexbox!
.wrapper li {list-style-type: none;}
.wrapper {
overflow: hidden;
background-color: red;
}
.wrapper .logo{
margin-right : 30px;
}
.wrapper a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.wrapper a:hover {
background-color: #ddd;
color: black;
}
.wrapper a.active {
background-color: #4CAF50;
color: white;
}
.topnav-right {
float: right;
}
<div class="wrapper">
<a class="active logo" href="#">Logo</a>
Home
Page 1
Page 2
<div class="topnav-right">
<li><a class="contact" href="#">Contact</a></li>
</div>
</div>

Make vertical dropdown same width as main menu

I tried to make a dropdown submenu (in this case 'Products') which has the same width as the mainmenu. The hover/active background colour should cover the entire width of the menu. It seems to be confined to stay within the above laying table.
Is there a way to expand towards the borders as well?
html,
body {
font-family: Arial, Helvetica, sans-serif;
}
.mainmenu li:hover .submenu {
display: inherit;
max-height: 200px;
line-height: 25px;
}
.submenu {
overflow: hidden;
max-height: 0;
width: 100%;
-webkit-transition: all 0.5s ease-out;
}
.easyflexMenu {
width: 150px;
height: 500px;
float: left;
color: #ffffff;
background-color: #229dfc;
border-radius: 5px;
/*bolling van de hoeken*/
padding: 10px;
}
.easyflexMenu a {
margin: -10px;
padding: 10px 10px 5px 15px;
width: 145px;
height: 50px;
display: block;
text-decoration: none;
line-height: 25px;
color: #ffffff;
background-color: #229dfc;
}
.easyflexMenu a:active {
color: #ffffff;
background-color: rgba(0, 0, 0, 0.5);
}
.easyflexMenu a:hover {
color: #ffffff;
background-color: rgba(0, 0, 0, 0.5);
}
li {
display: list-item;
text-align: -webkit-match-parent;
}
.easyflexMenu ul {
margin: 0px;
padding: 0px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
list-style-type: none;
}
ul,
menu,
dir {
display: block;
list-style-type: disc;
-webkit-margin-before: 1em;
-webkit-margin-after: 1em;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
-webkit-padding-start: 40px;
}
<div id="efmainmenu" class="easyflexMenu">
<nav class="navigation">
<ul class="mainmenu">
<li class="home">Home</li>
<li class="about">About</li>
<li class="products">Products
<ul class="submenu">
<li>Tops</li>
<li>Bottoms</li>
<li>Footwear</li>
</ul>
</li>
<li class="contact">Contact us</li>
</ul>
</nav>
</div>
I've made the CSS a little bit smaller and in this example you have a fix height of the submenu.
You could use jQuery's animate to solve it without a fix height of the submenu
.navigation ul {
display: inline-block;
margin: 0px;
padding: 0px;
list-style: none;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
}
.navigation ul > li {
display: block;
margin: 0px;
padding: 0px;
width: 170px;
min-height: 65px;
line-height: 65px;
}
.navigation ul > li a {
display: block;
height: 100%;
padding: 0px 15px;
line-height: inherit;
text-decoration: none;
color: #fff;
background-color: #229dfc;
}
.navigation ul > li a:active,
.navigation ul > li a:hover {
background-color: #114e7e;
}
.navigation ul > li .submenu {
display: inherit;
height: 0px;
overflow: hidden;
-webkit-transition: all 500ms ease-out;
transition: all 500ms ease-out;
}
.navigation ul > li a:active + .submenu,
.navigation ul > li a:hover + .submenu,
.navigation ul > li .submenu:active,
.navigation ul > li .submenu:hover {
height: 195px;
}
<div id="efmainmenu" class="easyflexMenu">
<nav class="navigation">
<ul class="mainmenu">
<li class="home">Home</li>
<li class="about">About</li>
<li class="products">Products
<ul class="submenu">
<li>Tops</li>
<li>Bottoms</li>
<li>Footwear</li>
</ul>
</li>
<li class="contact">Contact us</li>
</ul>
</nav>
</div>
Update: Elements below .submenu should not jump
Just add a position: absolute and z-index: 50 to the .navigation ul > li .submenu like this example
.navigation ul {
display: inline-block;
margin: 0px;
padding: 0px;
list-style: none;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
}
.navigation ul > li {
position: relative;
display: block;
margin: 0px;
padding: 0px;
width: 170px;
min-height: 65px;
line-height: 65px;
}
.navigation ul > li a {
display: block;
height: 100%;
padding: 0px 15px;
line-height: inherit;
text-decoration: none;
color: #fff;
background-color: #229dfc;
}
.navigation ul > li a:active,
.navigation ul > li a:hover {
background-color: #114e7e;
}
.navigation ul > li .submenu {
position: absolute;
display: inherit;
height: 0px;
overflow: hidden;
-webkit-transition: all 500ms ease-out;
transition: all 500ms ease-out;
z-index: 50;
}
.navigation ul > li a:active + .submenu,
.navigation ul > li a:hover + .submenu,
.navigation ul > li .submenu:active,
.navigation ul > li .submenu:hover {
height: 195px;
}
<div id="efmainmenu" class="easyflexMenu">
<nav class="navigation">
<ul class="mainmenu">
<li class="home">Home</li>
<li class="about">About</li>
<li class="products">Products
<ul class="submenu">
<li>Tops</li>
<li>Bottoms</li>
<li>Footwear</li>
</ul>
</li>
<li class="contact">Contact us</li>
</ul>
</nav>
</div>
The simple solution should be to make the UI as responsive as possible by ignoring the use of properties such as negative margin, fixed width until and unless required without no way around.
Also always reset default CSS margin and padding for every element in the beginning which is helpful to remove the white space around the elements and around the page.
I have modified your CSS a bit. If you still think it requires more width or space, try adding padding on the anchor element instead of fixed width to .easyflexMenu.
//Resetting the CSS
* {
margin: 0px;
padding: 0px;
}
//ENDS
html,
body {
font-family: Arial, Helvetica, sans-serif;
}
.mainmenu li:hover .submenu {
display: inherit;
max-height: 200px;
line-height: 25px;
}
.submenu {
overflow: hidden;
max-height: 0;
width: 100%;
-webkit-transition: all 0.5s ease-out;
}
.easyflexMenu {
height: 500px;
float: left;
color: #ffffff;
background-color: #229dfc;
border-radius: 5px;
}
.easyflexMenu a {
/*margin: -10px;*/
padding: 10px 10px 5px 15px; //Change this if you want more width.
width: 145px;
height: 50px;
display: block;
text-decoration: none;
line-height: 25px;
color: #ffffff;
background-color: #229dfc;
}
.easyflexMenu a:active {
color: #ffffff;
background-color: rgba(0, 0, 0, 0.5);
}
.easyflexMenu a:hover {
color: #ffffff;
background-color: rgba(0, 0, 0, 0.5);
}
li {
display: list-item;
text-align: -webkit-match-parent;
}
.easyflexMenu ul {
/*margin: 0px;
padding: 0px;*/
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
list-style-type: none;
}
ul,
menu,
dir {
display: block;
/*list-style-type: disc;
-webkit-margin-before: 1em;
-webkit-margin-after: 1em;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
-webkit-padding-start: 40px;*/
}

CSS add slogan into header

I have a header consists of a website name (at the left part) and a horizontal navigation menu (at the right part). My objective is to add a slogan under the site name. Meanwhile, the bottom of site name should still completely match with the bottom of menu elements, the only change is adding slogan.
Here are my header and a picture with expected result: https://jsfiddle.net/1nc9ch3x/1/
Give me please a hint how to figure it out. Thank you in advance!
body {
background: url(http://i.imgur.com/Asbdvgw.png);
font-family: 'Open Sans', sans-serif;
}
header {
width: 950px;
margin: auto;
position: relative;
background: #fff;
overflow: hidden;
}
.wrapper {
width: 950px;
margin: 0 auto;
}
header .logo {
display: inline;
border-left: 1px dashed #333333;
padding: 0 0 25px 10px;
text-decoration: none;
float: left;
font-size: 30px;
color: #cc3333;
margin: 25px 0px;
}
header nav {
float: right;
margin: 25px 0px;
}
header nav ul {
margin-top: 0px;
}
header nav ul li {
display: block;
float: left;
}
header nav ul li a {
text-decoration: none;
color: #333333;
font-size: 17px;
padding-top: 15px;
padding-bottom: 15px;
transition: all .2s linear;
-webkit-transition: all .2s linear;
-moz-transition: all .2s linear;
-o-transition: all .2s linear;
}
header nav ul li a.active,
header nav ul li a:hover {
color: #cc3333;
border-top: 1px dashed #cc3333;
border-bottom: 1px dashed #cc3333;
}
header li {
display: inline;
border-left: 1px dashed #cc3333;
padding: 10px 25px 10px 25px;
}
header li:first-child {
border: none;
}
<header>
<div class="wrapper">
<div class="logo">
Name
</div>
<nav>
<ul>
<li>Category 1
</li>
<li>Category 2
</li>
<li>Category 3
</li>
<li>Category 4
</li>
</ul>
</nav>
</div>
</header>
<br>
<br>
<center><font color="#fff">My goal:</font>
<br>
<br>
<img src="http://i.imgur.com/aW7k0QI.png">
This should do the trick : Fiddle : https://jsfiddle.net/1nc9ch3x/3/
HTML :
<div class="logo">
Name<span>Slogan</span>
</div>
CSS :
header .logo {
position:relative;
}
header .logo span {
white-space:nowrap;
color:black;
font-size:18px;
position:absolute;
bottom:0;
left:10px;
}
To achieve what you want is as easy as putting the following code inside <div class="logo">:
<p id = "slogan">Slogan should be right here</p>
Then, you can go in your CSS file and make the necessary changes for #slogan. Something like the following:
#slogan {
color: #0c0c0c;
font-size: 16px;
display: block;
margin-top: 5px;
}
You can check out this working demo or the following snippet.
Snippet:
body {
background: url(http://i.imgur.com/Asbdvgw.png);
font-family: 'Open Sans', sans-serif;
}
header {
width: 100%;
height: 100px;
margin: auto;
position: relative;
background: #fff;
overflow: hidden;
}
.wrapper {
width: 950px;
margin: 0 auto;
}
header .logo {
display: inline;
border-left: 1px dashed #333333;
padding: 0 0 25px 10px;
text-decoration: none;
float: left;
font-size: 30px;
color: #cc3333;
margin: 25px 0px;
}
header nav {
float: right;
margin: 25px 0px;
}
header nav ul {
margin-top: 0px;
}
header nav ul li {
display: block;
float: left;
}
header nav ul li a {
text-decoration: none;
color: #333333;
font-size: 17px;
padding-top: 15px;
padding-bottom: 15px;
transition: all .2s linear;
-webkit-transition: all .2s linear;
-moz-transition: all .2s linear;
-o-transition: all .2s linear;
}
header nav ul li a.active,
header nav ul li a:hover {
color: #cc3333;
border-top: 1px dashed #cc3333;
border-bottom: 1px dashed #cc3333;
}
header li {
display: inline;
border-left: 1px dashed #cc3333;
padding: 10px 25px 10px 25px;
}
header li:first-child {
border: none;
}
#slogan {
margin-top: 5px;
color: #0c0c0c;
font-size: 16px;
display: block;
}
<header>
<div class="wrapper">
<div class="logo">
Name
<p id="slogan">Slogan should be right here</p>
</div>
<nav>
<ul>
<li>Category 1
</li>
<li>Category 2
</li>
<li>Category 3
</li>
<li>Category 4
</li>
</ul>
</nav>
</div>
</header>
Get your code:
html:
<header>
<div class="wrapper">
<div class="logo">
<h4>
Name
</h4>
<p>your slogan here</p>
</div>
<nav>
<ul>
<li>Category 1</li>
<li>Category 2</li>
<li>Category 3</li>
<li>Category 4</li>
</ul>
</nav>
</div>
</header>
<br><br>
<center><font color="#fff">My goal:</font><br><br>
<img src="http://i.imgur.com/aW7k0QI.png">
css:
body {
background: url(http://i.imgur.com/Asbdvgw.png);
font-family: 'Open Sans', sans-serif;
margin:0;
}
header {
width: 950px;
margin: auto;
position: relative;
background: #fff;
overflow: hidden;
}
.wrapper {
width: 950px;
margin: 0 auto;
}
header .logo{
border-left: 1px dashed #333333;
padding:5px 10px;
}
header .logo h4{
padding: 0px ;
text-decoration: none;
font-size: 30px;
color: #cc3333;
padding: 10px;
padding-bottom:0;
}
.logo h4{
margin:0;
padding:0;
}
.logo p{
color:rgba(0,0,0,0.7);
margin:0;
padding:0 10px;
}
header nav{
position:absolute;
right:0;
top:0;
margin: 0px 0px;
}
header nav ul{
margin: 0px;
}
header nav ul li{
display: block;
float: left;
margin: 0px;
}
header nav ul li a{
text-decoration: none;
color: #333333;
font-size: 17px;
padding-top: 15px;
padding-bottom: 15px;
transition: all .2s linear;
-webkit-transition: all .2s linear;
-moz-transition: all .2s linear;
-o-transition: all .2s linear;
}
header nav ul li a.active,
header nav ul li a:hover{
color: #cc3333;
border-top: 1px dashed #cc3333;
border-bottom: 1px dashed #cc3333;
}
header li {
display: inline;
border-left: 1px dashed #cc3333;
padding: 10px 25px 10px 25px;
}
header li:first-child {
border: none;
}
Here's an updated Fiddle.
Critical CSS:
header .slogan {
color: #000;
font-size: 20px;
display: block;
}
And HTML:
<div class="logo">
Name
<span class="slogan">Tagline here</span>
</div>

Tricky horizontal center in css : floating elements only

I can't find a way to properly align a button in the middle of floating elements.
button {
float:left;
}
header {
overflow: hidden;
background: #222;
}
header a, header label {
display: block;
padding: 20px;
color: #fff;
text-decoration: none;
line-height: 20px;
}
header a:hover, header label:hover { color: #aaa; }
header label {
float: right;
padding: 18px 20px;
cursor: pointer;
}
header label:after {
content: "\2261";
font-size: 1.8em;
}
.logo {
float: left;
font-weight: bold;
font-size: 1.5em;
}
nav {
float: right;
max-height: 0;
width: 100%;
-webkit-transition: max-height 0.3s;
-moz-transition: max-height 0.3s;
-o-transition: max-height 0.3s;
transition: max-height 0.3s;
}
nav ul {
margin: 0;
padding: 0;
padding-bottom: 10px;
}
nav li {
display: block;
text-align: center;
}
nav a {
padding: 10px;
width: 100%;
}
#nav { display: none; }
#nav:checked ~ nav {
max-height: 200px; /* This can be anything bigger than your nav height. The transition duration works with this */
}
#media only screen and (min-width: 700px) {
header label { display: none; }
nav {
width: auto;
max-height: none;
}
nav ul {
padding: 0;
padding-right: 10px;
}
nav li {
display: inline-block;
text-align: left;
}
header nav a {
display: inline-block;
padding: 20px 10px;
width: auto;
}
}
<header>
<a class="logo" href="http://minimaldev.com">Minimal Menu</a>
<input id="nav" type="checkbox">
<label for="nav"></label>
<button>centered button ?</button>
<nav>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
</ul>
</nav>
</header>
See example also on codepen
I tried the display-table trick, but it breaks the navbar behaviour on small device (responsive).
I also tried this technique , but I have the same problem.
Any idea ? I thought about using calc(), but I can't find the right formula.
I made a couple of edits:
added text-align: center to the parent element of the button
bumped the button off the top edge with manual pixel adjustments (assuming the design stays rigid in terms of logo size, it is not a responsive solution because of the non-responsive nature of font and padding sizing).
Here it is in a CodePen
HTML:
<header>
<a class="logo" href="http://minimaldev.com">Minimal Menu</a>
<input id="nav" type="checkbox">
<label for="nav"></label>
<button>centered button</button>
<nav>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
</ul>
</nav>
</header>
CSS:
button{
margin-top: 18px;
}
header {
text-align: center;
overflow: hidden;
background: #222;
}
header a, header label {
display: block;
padding: 20px;
color: #fff;
text-decoration: none;
line-height: 20px;
}
header a:hover, header label:hover { color: #aaa; }
header label {
float: right;
padding: 18px 20px;
cursor: pointer;
}
header label:after {
content: "\2261";
font-size: 1.8em;
}
.logo {
float: left;
font-weight: bold;
font-size: 1.5em;
}
nav {
float: right;
max-height: 0;
width: 100%;
-webkit-transition: max-height 0.3s;
-moz-transition: max-height 0.3s;
-o-transition: max-height 0.3s;
transition: max-height 0.3s;
}
nav ul {
margin: 0;
padding: 0;
padding-bottom: 10px;
}
nav li {
display: block;
text-align: center;
}
nav a {
padding: 10px;
width: 100%;
}
#nav { display: none; }
#nav:checked ~ nav {
max-height: 200px; /* This can be anything bigger than your nav height. The transition duration works with this */
}
#media only screen and (min-width: 700px) {
header label { display: none; }
nav {
width: auto;
max-height: none;
}
nav ul {
padding: 0;
padding-right: 10px;
}
nav li {
display: inline-block;
text-align: left;
}
header nav a {
display: inline-block;
padding: 20px 10px;
width: auto;
}
}

Centering Menu Links

I'm trying to center the Menu Links but I can't. (Link to my website). As you can notice, the 'Home' and 'Staff' links are aligned at the left side of the page, but I want them to be centered. (With percentage, if possible)
Here you have the CSS Code
/*Navigation*/
#menu {
width: 100%;
float: left;
margin: 0 0 3em 0;
padding: 0;
list-style: none;
background-color: #1C1C1C;
margin-top:85px;
}
#menu li {
float: left; }
#menu li a {
display: block;
padding: 30px 30px;
text-decoration: none;
font-weight: bold;
color: #fff;
transition: background-color 0.5s ease;
transition: color 0.5s ease;
}
#menu li a:hover {
color: #69bfe7;
background-color: #2E2E2E;
transition: background-color 0.5s ease;
transition: color 0.5s ease;
}
Here the HTML Code
<!-- Here's all it takes to make this navigation bar. -->
<ul id='menu'>
<li><a href='#'>Home</a></li>
<li><a href='#'>Staff</a></li>
</ul>
<!-- That's it! -->
Try this:
#menu {
background-color: #1c1c1c;
float: left;
list-style: outside none none;
margin: 85px 0 3em;
padding: 0;
text-align: center;
width: 100%;
}
#menu li {
display: inline-block;
/* float: left; */
}
This should do the trick:
#menu {
width: 100%;
margin: 0 0 3em 0;
padding: 0;
list-style: none;
background-color: #1C1C1C;
margin-top:85px;
text-align: center;
}
#menu li {
display: inline-block;
}