Extra space next to menu? - html

I have a menu that spans across the page. I have its wrapper set to 100% and correctly, it spans completely across its container. I have for menu items set at 25% each however, there is around 20px space to the left of the menu revealing the background color. Regardless of sizes and margin:0 auto, the space remains.
.center{
margin:0 auto;
width:100%;
height:100%;
background-color:#3c87bc;
padding:0;
}
#top_forums_menu{
width:100%;
height:24px;
background-color:#5dbcff;
position:relative;
}
ul#top_forums_menu_bars {
list-style-type: none;
margin:0 auto;
}
ul#top_forums_menu_bars li {
float: left;
width:25%;
height: 100%;
overflow:hidden;
-webkit-box-shadow: 0 6px 2px -4px black;
-moz-box-shadow: 0 6px 2px -4px black;
box-shadow: 0 6px 2px -4px black;
transition: all .25s ease-in-out;
-moz-transition: all .25s ease-in-out;
-webkit-transition: all .25s ease-in-out;
}
ul#top_forums_menu_bars li:hover{
border-bottom:5px solid #3a5871;
}
ul#top_forums_menu_bars li a{
display: inline-block;
width: 100%;
height: 100%;
opacity:1;
text-decoration:none;
transition: opacity .5s ease-in-out;
-moz-transition: opacity .5s ease-in-out;
-webkit-transition: opacity .5s ease-in-out;
line-height:10px;
padding-top:7px;
text-align:center;
font-family: Tahoma, Verdana, Segoe, sans-serif;
font-size:12px;
color:white;
}
ul#top_forums_menu_bars li a:hover {
opacity:.8;
}
<div id='top_forums_menu'>
<div class='center'>
<ul id='top_forums_menu_bars'>
<li><a href='' style='background-color:#5dbcff;'>Profile</a></li>
<li><a href='' style='background-color:#5dbcff;'>Account Settings</a></li>
<li><a href='' style='background-color:#5dbcff;'>My Content</a></li>
<li><a href='' style='background-color:#5dbcff;'>MyOACH</a></li>
</ul>
</div>
</div>

<ul> has a default padding which can be removed with the following rule:
ul#top_forums_menu_bars
{
padding-left: 0;
}

Just remove the left-padding
ul#top_forums_menu_bars {
list-style-type: none;
margin: 0 auto;
padding-left: 0;
}
https://jsfiddle.net/36ywxtyk/4/

The problem is that <ul> elements (along with <menu> and <dir> elements have a built-in browser rendering of padding-start: 40px. This is what is causing the offset that you see.
The easiest way to resolve this is to explicitly give your ul#top_forums_menu_bars a padding of 0, as can be seen in the following:
.center {
margin: 0 auto;
width: 100%;
height: 100%;
background-color: #3c87bc;
padding: 0;
}
#top_forums_menu {
width: 100%;
height: 24px;
background-color: #5dbcff;
position: relative;
}
ul#top_forums_menu_bars {
list-style-type: none;
margin: 0 auto;
padding: 0;
}
ul#top_forums_menu_bars li {
float: left;
width: 25%;
height: 100%;
overflow: hidden;
-webkit-box-shadow: 0 6px 2px -4px black;
-moz-box-shadow: 0 6px 2px -4px black;
box-shadow: 0 6px 2px -4px black;
transition: all .25s ease-in-out;
-moz-transition: all .25s ease-in-out;
-webkit-transition: all .25s ease-in-out;
}
ul#top_forums_menu_bars li:hover {
border-bottom: 5px solid #3a5871;
}
ul#top_forums_menu_bars li a {
display: inline-block;
width: 100%;
height: 100%;
opacity: 1;
text-decoration: none;
transition: opacity .5s ease-in-out;
-moz-transition: opacity .5s ease-in-out;
-webkit-transition: opacity .5s ease-in-out;
line-height: 10px;
padding-top: 7px;
text-align: center;
font-family: Tahoma, Verdana, Segoe, sans-serif;
font-size: 12px;
color: white;
}
ul#top_forums_menu_bars li a:hover {
opacity: .8;
}
<div id='top_forums_menu'>
<div class='center'>
<ul id='top_forums_menu_bars'>
<li><a href='' style='background-color:#5dbcff;'>Profile</a></li>
<li><a href='' style='background-color:#5dbcff;'>Account Settings</a></li>
<li><a href='' style='background-color:#5dbcff;'>My Content</a></li>
<li><a href='' style='background-color:#5dbcff;'>MyOACH</a></li>
</ul>
</div>
</div>
Alternatively, you could apply a global low-specificity rule of:
* {
margin: 0;
padding: 0;
}
This will override all of the browser padding / margin quirks, while still having a low enough specificity for any individual selectors to override these rules.

Related

How to Create a Smooth Dropping Animation in CSS?

I am trying to create a smooth animation of my nav-bar in CSS here's my HTML Code-
<body>
<nav class="navbar">
<ul class="nav-list another">
<li><n>Engine</n></li>
<li>Home</li>
<li>About</li>
<li>Contact Us</li>
<li><button type="button" id="mysearch">More</button></li>
</ul>
</nav>
<hr>
</body>
</html>
Here's my CSS Code-
*{
margin: 0;
padding: 0;
}
html{
background-color: white;
background-image: url("img/ManHattanImage.webp");
}
li{
align-items: left;
width: 100px;
height: 100%;
display: inline-block;
margin-right: 170px;
font-size: 20px;
/* background-color: black; */
color: black;
font-size: 20px;
}
hr{
color: black;
margin-top: 30px;
}
n{
/* background-color: black; */
color: white;
font-size: 40px;
font-style: bold;
font-family: "Lucida Console", "Courier New", monospace;
margin-left: 20px;
margin-top: 30px;
}
a {
text-decoration: none;
color: white;
}
a:visited { text-decoration: none; }
a:hover {
text-decoration: none;
/* background-color: black; */
}
a:focus { text-decoration: none; }
a:hover, a:active { text-decoration: none; }
nav:hover{
height:300px;
}
I want a clean Animation like of a good dropdown menu navbar and with clear overlaps, Also I may add some more elements inside the navbar (With Further Updates)?
This is how to make a dropdown menu but I'm not sure how to do an animation. I hope this is what you meant by the dropdown menu.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.dropbtn {
background-color: #ac0d0d;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #ffffff;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: rgb(18, 19, 85);
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {background-color: #ddd;}
.dropdown:hover .dropdown-content {display: block;}
.dropdown:hover .dropbtn {background-color: #ac0d0d;}
</style>
</head>
<body>
<div class="dropdown">
<button class="dropbtn">Dropdown menu</button>
<div class="dropdown-content">
first
second
third
</div>
</div>
</body>
</html>
Animation Drop down menu on hover
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
nav {
width: 100%;
height: 80px;
background: #222;
}
ul {
text-align: center;
}
ul li {
font: 13px Verdana, 'Lucida Grande';
cursor: pointer;
-webkit-transition: padding .05s linear;
-moz-transition: padding .05s linear;
-ms-transition: padding .05s linear;
-o-transition: padding .05s linear;
transition: padding .05s linear;
}
ul li.drop {
position: relative;
}
ul > li {
display: inline-block;
}
ul li a {
line-height: 80px;
padding: 0 20px;
height: 80px;
color: #777;
-webkit-transition: all .1s ease-out;
-moz-transition: all .1s ease-out;
-ms-transition: all .1s ease-out;
-o-transition: all .1s ease-out;
transition: all .1s ease-out;
}
ul li a:hover {
color: #eee;
}
.dropOut .triangle {
width: 0;
height: 0;
position: absolute;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-bottom: 8px solid white;
top: -8px;
left: 50%;
margin-left: -8px;
}
.dropdownContain {
width: 160px;
position: absolute;
z-index: 2;
left: 50%;
margin-left: -80px; /* half of width */
top: -400px;
}
.dropOut {
width: 160px;
background: white;
float: left;
position: relative;
margin-top: 0px;
opacity: 0;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
-webkit-box-shadow: 0 1px 6px rgba(0,0,0,.15);
-moz-box-shadow: 0 1px 6px rgba(0,0,0,.15);
box-shadow: 0 1px 6px rgba(0,0,0,.15);
-webkit-transition: all .1s ease-out;
-moz-transition: all .1s ease-out;
-ms-transition: all .1s ease-out;
-o-transition: all .1s ease-out;
transition: all .1s ease-out;
}
.dropOut ul {
float: left;
padding: 10px 0;
}
.dropOut ul li {
text-align: left;
float: left;
width: 125px;
padding: 12px 0 10px 15px;
margin: 0px 10px;
color: #777;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
-webkit-transition: background .1s ease-out;
-moz-transition: background .1s ease-out;
-ms-transition: background .1s ease-out;
-o-transition: background .1s ease-out;
transition: background .1s ease-out;
}
.dropOut ul li:hover {
background: #f6f6f6;
}
ul li:hover a { color: white; }
ul li:hover .dropdownContain { top: 65px; }
ul li:hover .underline { border-bottom-color: #777; }
ul li:hover .dropOut { opacity: 1; margin-top: 8px; }
</style>
<body>
<nav>
<ul>
<li class="drop">
You
<div class="dropdownContain">
<div class="dropOut">
<div class="triangle"></div>
<ul>
<li>Plan</li>
<li>Account Settings</li>
<li>Switch Account</li>
<li>Sign Out</li>
</ul>
</div>
</div>
</li>
</ul>
</nav>
</body>
</html>

How to make padding to not affect width, height and size

I want to padding work like absolute positioning. So It wont hurt other things.
I'm using Hover.css by IanLunn. I want the line animation to be under the List item.
Because of that I'm using padding to position the hover animation:
https://imgur.com/a/sD1on0I
In the image, line animation apears too close to text. I want it to be little far from that without hurting other elements.
I can move it with padding but it does hurt other elements and box-sizing:border-box !important; does not change anything.
.navbarUlDiv {
margin-top:35px;
}
.navbarUl {
list-style: none;
padding: 0;
font-size: 0;
}
.navbarLi {
padding: 4px 5px 4px 5px !important;
margin: 0px 20px 0px 20px;
display: inline;
color: #595959;
font-size: 16px;
transition: 0.4s ease-in-out;
}
.navbarLi a{
padding-bottom: 80px;
}
<div class="navbarUlDiv">
<ul class="navbarUl text-center">
<li class="navbarLi">1</li>
<li class="navbarLi">2</li>
<li class="navbarLi">3</li>
<li class="navbarLi">4</li>
</ul>
</div>
If i am right u can try this
.navbarUlDiv {
margin-top:35px;
}
.navbarUl {
list-style: none;
padding: 0;
font-size: 0;
}
.navbarLi {
padding: 4px 5px 4px 5px !important;
margin: 0px 20px 0px 20px;
display: inline;
color: #595959;
font-size: 16px;
transition: 0.4s ease-in-out;
}
.navbarLi a{
box-sizing:border-box !important;
padding-bottom:0;
position:relative
}
.navbarLi a:after{
background:red;
content:"";
position:absolute;
left:0px;
right:0px;
width:0;
height:3px;
bottom:-10px;
transition: all ease 0.3s;
opacity:0;
margin:auto;
}
.navbarLi a:hover:after{
width:100%;
opacity:1;
}
<div class="navbarUlDiv">
<ul class="navbarUl text-center">
<li class="navbarLi">1</li>
<li class="navbarLi">2</li>
<li class="navbarLi">3</li>
<li class="navbarLi">4</li>
</ul>
</div>

CSS width transition out not working

Below is the HTML and CSS I'm using. Unfortunately the questions already asked do not give the answer required. Basically it decreases the width of all siblings and increases the one that is hovered over. I'm using ease-in-out but the OUT part of the transition just instantaneously jumps back to its original state.
html {
background: #000066;
}
body {
height: 100%;
background: #cfcfd0;
margin: 4% 4% 4% 4%;
}
#title {
background: ;
text-align: center;
margin: 2% 2%;
padding: 2% 2%;
}
#nav {
width: 90%;
overflow: auto;
margin: 0 auto;
padding: 0px 0px 0px 0px
}
ul {
margin: 4% auto;
padding: 0;
width: 100%;
list-style-type: none;
overflow: auto;
}
li {
box-sizing: border-box;
text-align: center;
display: inline-block;
float: left;
width: 33.33%;
padding: 2% 0;
margin: 0%;
background: blue;
border-top: 1px solid black;
border-bottom: 1px solid black;
border-right: 1px solid black;
}
li:first-child {
border-left: 1px solid black;
}
li:last-child {
border-right: 1px solid black;
}
a {
color: black;
text-decoration: none;
}
ul:hover > li:hover {
width: 37.33%;
color: white;
background: darkblue;
-webkit-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-ms-transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
transition: all 300ms ease-in-out;
}
ul:hover > li {
width: 31.33%;
-webkit-transition: width 300ms ease-in-out;
-moz-transition: width 300ms ease-in-out;
-ms-transition: width 300ms ease-in-out;
-o-transition: width 300ms ease-in-out;
transition: width 300ms ease-in-out;
}
<div id="title">
<h1>Projects Home</h1>
</div>
<div id="nav">
<ul>
<li>Project 1
</li>
<li>Project 2
</li>
<li>Project 3
</li>
</ul>
</div>
I can't figure out why this is.
Any CSS property gets applied to an element only when the selector is matched. When transition property is specified under the :hover selector, they naturally get applied only when the hover is on. When we hover out, they just snap back because the transition setting is no longer applicable for the element.
In your case, since transition is specified only within ul:hover > li:hover and ul:hover > li it gets applied only when the mouse is over an li or when the mouse is atleast over the ul (that is when we are moving from one li to another while still being inside the ul boundaries).
To get the transition to work properly even during mouse out, it should be specified within the li selector like in the below snippet.
html {
background: #000066;
}
body {
height: 100%;
background: #cfcfd0;
margin: 4% 4% 4% 4%;
}
#title {
background: ;
text-align: center;
margin: 2% 2%;
padding: 2% 2%;
}
#nav {
width: 90%;
overflow: auto;
margin: 0 auto;
padding: 0px 0px 0px 0px
}
ul {
margin: 4% auto;
padding: 0;
width: 100%;
list-style-type: none;
overflow: auto;
}
li {
box-sizing: border-box;
text-align: center;
display: inline-block;
float: left;
width: 33.33%;
padding: 2% 0;
margin: 0%;
background: blue;
border-top: 1px solid black;
border-bottom: 1px solid black;
border-right: 1px solid black;
-webkit-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-ms-transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
transition: all 300ms ease-in-out;
}
li:first-child {
border-left: 1px solid black;
}
li:last-child {
border-right: 1px solid black;
}
a {
color: black;
text-decoration: none;
}
ul:hover > li:hover {
width: 37.33%;
color: white;
background: darkblue;
}
ul:hover > li {
width: 31.33%;
}
<div id="title">
<h1>Projects Home</h1>
</div>
<div id="nav">
<ul>
<li>Project 1
</li>
<li>Project 2
</li>
<li>Project 3
</li>
</ul>
</div>
Remove the > on ul:hover > li to ul:hover li:
html {
background: #000066;
}
body {
height: 100%;
background: #cfcfd0;
margin: 4% 4% 4% 4%;
}
#title {
background: ;
text-align: center;
margin: 2% 2%;
padding: 2% 2%;
}
#nav {
width: 90%;
overflow: auto;
margin: 0 auto;
padding: 0px 0px 0px 0px
}
ul {
margin: 4% auto;
padding:0;
width: 100%;
list-style-type: none;
overflow: auto;
}
li {
box-sizing: border-box;
text-align: center;
display: inline-block;
float:left;
width: 33.33%;
padding: 2% 0;
margin: 0%;
background: blue;
border-top: 1px solid black;
border-bottom: 1px solid black;
border-right: 1px solid black;
}
li:first-child {
border-left: 1px solid black;
}
li:last-child {
border-right: 1px solid black;
}
a {
color: black;
text-decoration: none;
}
ul:hover > li:hover{
width: 37.33%;
color: white;
background: darkblue;
-webkit-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-ms-transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
transition: all 300ms ease-in-out;
}
ul:hover li {
width: 31.33%;
-webkit-transition: width 300ms ease-in-out;
-moz-transition: width 300ms ease-in-out;
-ms-transition: width 300ms ease-in-out;
-o-transition: width 300ms ease-in-out;
transition: width 300ms ease-in-out;
}
<div id= "title">
<h1>Projects Home</h1>
</div>
<div id= "nav">
<ul>
<li>Project 1</li>
<li>Project 2</li>
<li>Project 3</li>
</ul>
</div>

Dropdown menu to display over DIV

I am trying to create a simple CSS dropdown menu, the function is correct but I am having issues when I place it inside a holding DIV. The menu expands inside the DIV and adds scrolling bars.
I have tried hiding the overflow and positioning the elements but it has no effect:
JSFIDDLE
body
{
font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
padding: 20px 50px 150px;
font-size: 13px;
text-align: center;
}
.dropdown
{
text-align: left;
display: inline;
margin: 0;
padding: 0px 4px 0px 0px;
list-style: none;
}
.dropdown li
{
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
/*padding: 15px 20px;*/
background: #fff;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}
.dropdown li:hover
{
background: #555;
color: #fff;
}
.dropdown li ul
{
padding: 0;
position: absolute;
top: 18px;
left: 0;
width: 150px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
}
.dropdown li ul li
{
display: block;
color: #000;
padding-bottom: 5px;
}
.dropdown li ul li:hover
{
background: #666;
}
.dropdown li:hover ul
{
display: block;
opacity: 1;
visibility: visible;
}
<div style="box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.08), 1px 1px 4px rgba(255, 255, 255, 0.08) inset;border: 1px solid #DDD; overflow: auto; background-color: #FFF; text-align: center; border-radius: 10px; width:100%; height:50px;">
<ul class="dropdown">
<li>Section1
<ul>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</li>
</ul>
</div>
try like this: JSFIDDLE
.dropdown {
text-align: left;
display: inline-block;
margin: 0;
padding: 0px 4px 0px 0px;
list-style: none;
position:absolute;
top:0;
}
HTML:
<div style="box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.08), 1px 1px 4px rgba(255, 255, 255, 0.08) inset;border: 1px solid #DDD;
background-color: #FFF;
text-align: center;
border-radius: 10px;
width:100%;
height:50px; position:relative;">
Add position relative to div and remove overflow property. then add position:absolute to dropdown. Hope this helps !!
Code With Snippet below
body
{
font-family:'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
padding: 20px 50px 150px;
font-size: 13px;
text-align: center;
}
.dropdown
{
text-align: left;
display: inline-block;
margin: 0;
padding: 0px 4px 0px 0px;
list-style: none;
position:absolute;
top:0;
}
.dropdown li
{
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
/*padding: 15px 20px;*/
background: #fff;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}
.dropdown li:hover
{
background: #555;
color: #fff;
}
.dropdown li ul
{
padding: 0;
position: absolute;
top: 18px;
left: 0;
width: 150px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
}
.dropdown li ul li
{
display: block;
color: #000;
padding-bottom: 5px;
}
.dropdown li ul li:hover
{
background: #666;
}
.dropdown li:hover ul
{
display: block;
opacity: 1;
visibility: visible;
}
<div style="box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.08), 1px 1px 4px rgba(255, 255, 255, 0.08) inset;border: 1px solid #DDD;background-color: #FFF;text-align: center;border-radius: 10px;width:100%;height:50px; position:relative;">
<ul class="dropdown">
<li>Section1
<ul>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</li>
</ul>
</div>
Give the .dropdown a position absolute; as well.
Fiddle
please try this one:
please Add .dropdown css like this:position absolute;
JSFIDDLE
body
{
font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
padding: 20px 50px 150px;
font-size: 13px;
text-align: center;
}
.dropdown
{
position: absolute;
text-align: left;
display: inline;
margin: 0;
padding: 0px 4px 0px 0px;
list-style: none;
}
.dropdown li
{
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
/*padding: 15px 20px;*/
background: #fff;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}
.dropdown li:hover
{
background: #555;
color: #fff;
}
.dropdown li ul
{
padding: 0;
position: absolute;
top: 18px;
left: 0;
width: 150px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
}
.dropdown li ul li
{
display: block;
color: #000;
padding-bottom: 5px;
}
.dropdown li ul li:hover
{
background: #666;
}
.dropdown li:hover ul
{
display: block;
opacity: 1;
visibility: visible;
}
<div style="box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.08), 1px 1px 4px rgba(255, 255, 255, 0.08) inset;border: 1px solid #DDD;overflow: auto;background-color: #FFF;text-align: center;border-radius: 10px;width:100%;height:50px;">
<ul class="dropdown">
<li>Section1
<ul>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</li>
</ul>
</div>

My drop down menu is hidden behind my section tag

My drop down menu is hidden behind my "mainsection" tag and I'm not sure what I can do to expose it. It needs to lay on top of the "mainsection" tag area and not behind it.
Here is the jsfiddle : http://jsfiddle.net/nSmZ9/
and here is the html code
<header>
<ul class="right-nav-after-login">
<li>Home</li>
<li>About</li>
<li>
Menu
<ul>
<li>Account</li>
<li>My Gifts</li>
<li>Log off</li>
</ul>
</li>
<li>Contact</li>
</ul>
</header>
<article>
<section class="mainsection"></section>
</article>
here is my css
header {
height: 66px;
margin-left: 75px;
margin-right: 75px;
border: 2px solid black;
}
.mainsection {
background-color: #a6dbed;
height: 500px;
position: relative;
}
.right-nav-after-login {
float: right;
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
-webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
-moz-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
}
.right-nav-after-login li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 20px;
background: #fff;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}
.right-nav-after-login li:hover {
background: #555;
color: #fff;
}
.right-nav-after-login li ul {
padding: 0;
position: absolute;
top: 48px;
left: 0;
width: 150px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
}
.right-nav-after-login li ul li {
background: #555;
display: block;
color: #fff;
text-shadow: 0 -1px 0 #000;
}
.right-nav-after-login li ul li:hover { background: #666; }
.right-nav-after-login li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
.mainsection is defined later in your HTML than the menu, and since both are taken out of the regular flow, .mainsection will cover the menu . I'd recommend a more natural layout but lacking that, you can try this:
.right-nav-after-login, .right-nav-after-login * {
z-index: 1;
}
This will guarantee the menu and everything within to be above everything else, as long as the elements have position set to anything except static.
You can use z-index to specify the vertical stack order of elements. (Note that in order for z-index to work, an element must have absolute or relative positioning.)
There are different ways to do this. You just need to ensure that the element you want on top has a higher z-index. Here is one solution:
.mainsection {
....
z-index:1;
}
.right-nav-after-login li ul li {
....
position:relative;
z-index:2;
}
See demo
Take this off of .mainsection.
position: relative;
//inset this code
.right-nav-after-login li ul{z-index:100;}