overlap off by 1px in Firefox and IE but not in Chrome - css

In Chrome the ul li ul border is exact over de border of the menu ul, but in Internet Explorer and Firefox it's off by 1px.
http://jsfiddle.net/5qasu929/
#menu ul li ul {
display:none;
position:absolute;
z-index:999;
height:auto;
margin-top:16px;
margin-left:-0px;
background-color:#EFEFEF;
border-bottom:1px solid #C7C7C7;
border-left:1px solid #C7C7C7;
border-right:1px solid #C7C7C7;
}
#menu ul li {
display:table-cell;
height:50px;
vertical-align:middle;
border-bottom:1px solid #C7C7C7;
margin-left:0;
}
How can I fix this?

A couple of changes should make this more uniform across browsers:
Add position:relative; to #menu ul li to make the child ul position relative to it
Add top:50px; to #menu ul li ul. This is the same as the height of the parent li
Remove margin-top:16px; from #menu ul li ul
#menu {
width: 950px;
margin: 0px auto;
list-style: none;
position: relative;
}
#menu ul {
list-style: none;
float: left;
}
#menu ul li {
display: table-cell;
height: 50px;
vertical-align: middle;
border-bottom: 1px solid #C7C7C7;
margin-left: 0;
position: relative; /*Add*/
}
#menu ul li a {
font-size: 18px;
color: #024fff;
text-decoration: none;
font-family: 'Raleway', sans-serif;
padding: 5px;
}
#menu ul li:hover {
background-color: #E3E3E3;
border-bottom: 1px solid #024fff;
-webkit-transition: background-color 200ms linear;
-moz-transition: background-color 200ms linear;
-o-transition: background-color 200ms linear;
-ms-transition: background-color 200ms linear;
transition: background-color 200ms linear;
}
#menu ul li ul {
display: none;
position: absolute;
z-index: 999;
height: auto;
/*margin-top:16px;Remove*/
margin-left: -0px;
background-color: #EFEFEF;
border-bottom: 1px solid #C7C7C7;
border-left: 1px solid #C7C7C7;
border-right: 1px solid #C7C7C7;
top: 50px;/*Add*/
}
#menu ul li:hover > ul {
display: block;
border-top: 1px solid #024fff;
}
#menu ul li ul li {
min-width: 80px;
display: block;
height: 23px;
padding: 9px 35px 0px 5px;
border: 0px;
}
#menu ul li ul li:hover {
border-bottom: 0px;
}
#menu ul li ul li:before {
content: '- \00a0 ';
color: #024fff;
}
#menu ul li ul li a {
font-size: 16px;
padding: 3px;
}
<div id="menu">
<ul>
<li>Home
<ul>
<li>Sub1
</li>
<li>Sub1
</li>
<li>Sub1
</li>
</ul>
</li>
<li>Home2
<ul>
<li>Sub1
</li>
<li>Sub1
</li>
<li>Sub1
</li>
</ul>
</li>
<li>Home3
</li>
<li>Home4
<ul>
<li>Sub1
</li>
<li>Sub1
</li>
<li>Sub1
</li>
</ul>
</li>
</ul>
</div>

Use border-box property of css,
Specify that <li> elements should have padding and border included in
the element's total width and height:
#menu ul li {
box-sizing:border-box;
margin-top:-1px;
}

You should use the A tag height within a parent LI in order to position your sub menu
First, add a display:block and height:100% to your A:
#menu ul li a {
font-size:18px;
color:#024fff;
text-decoration:none;
font-family: 'Raleway', sans-serif;
padding:5px;
display:block;
height:100%;
}
Delete Li's height (Height will depend on the font-size & padding of your A tag
#menu ul li {
display:table-cell;
height:auto;
vertical-align:middle;
border-bottom:1px solid #C7C7C7;
margin-left:0;
}
And finally remove margin-top toi submenu :
#menu ul li ul {
display:none;
position:absolute;
z-index:999;
height:auto;
/*margin-top:16px;*/
margin-left:-0px;
background-color:#EFEFEF;
border-bottom:1px solid #C7C7C7;
border-left:1px solid #C7C7C7;
border-right:1px solid #C7C7C7;
}
Prevent submenu > a from being display:block:
#menu ul li ul li a {
font-size:16px;
padding:3px;
display:inline;
}
Live example

Related

Navigation Link Hover Border-top have 2 color [duplicate]

This question already has answers here:
How to create multi-color border with CSS?
(3 answers)
Closed 3 years ago.
I'm having problem in my website that I made. When I hover the navigation link I want the border-top have to different color. But when I tried it many times its not working.
result when hovered | expected result
<ul class="h_nav_list">
<li>HOME</li>
<li>PROFILE</li>
<li>ACTIVITY</li>
ul { padding:15px 0; }
ul li { display:inline-block; font-size:16px; padding:10px; }
ul li a { text-decoration:none; color:#222; font-weight:bold; padding-top:50px; }
ul li a.active,
ul li a:hover { color:#014880; border-top:7px solid; width:50%; }
ul li a.list:hover { border-top:7px solid #1880C9; width:50%; }
You have to use after before to achieve this, please check snippet.
ul { padding:15px 0; }
ul li { display:inline-block; font-size:16px; padding:10px;position:relative; }
ul li a { text-decoration:none; color:#222; font-weight:bold; padding-top:50px; }
ul li a.active,
ul li a:hover { color:#014880; border-top:7px solid; width:50%; }
ul li a.list:hover { border-top:7px solid #1880C9; width:50%; }
ul li a:hover:after{position:absolute; width:50%; background:#000; height:5px; content:''; left:0px; top:0px;}
ul li a:hover:before{position:absolute; width:50%; background:#ff0000; height:5px; content:''; right:0px; top:0px;}
<ul class="h_nav_list">
<li>HOME</li>
<li>PROFILE</li>
<li>ACTIVITY</li>
I have created a demo using after and before. Please check this:
ul { padding:15px 0; }
.h_nav_list li {
position: relative;
display: inline-block;
font-size:16px;
padding:20px 10px;
list-style: none;
}
.h_nav_list li a {
color: #000;
text-decoration: none;
}
.h_nav_list li::before,
.h_nav_list li::after {
position: absolute;
top: 0;
left: 0;
width: 50%;
height: 7px;
opacity: 0;
content: '';
transition: .3s all;
}
.h_nav_list li::before {
background-color: #014880;
}
.h_nav_list li::after {
left: 50%;
background-color: #1880C9;
}
.h_nav_list li.active::before,
.h_nav_list li.active::after,
.h_nav_list li:hover::before,
.h_nav_list li:hover::after {
opacity: 1;
}
<ul class="h_nav_list">
<li><a href="index.html class="list active"> HOME </a </li>
<li>PROFILE</li>
<li>ACTIVITY</li>
</ul>
Edit : (See comments below..)
You can add a linear-gradient to your <a> or <li> element with the border-image property.
ul li { display: inline-block; font-size: 20px; list-style: none; border-top: 4px solid darkblue; }
ul li:hover { border-image: linear-gradient(to right, darkblue 50%, aquamarine 0) 4; }
ul li a { text-decoration: none; color: black; }
<ul>
<li>One</li>
<li>Two</li>
<ul>
Your HTML has a bug, the href of HOME wasn't closed with the double quote
The border-top does apply but because of the padding-top: 50px, it wasn't visible. I reduced it to 5px
ul {
padding: 15px 0;
}
ul li {
display: inline-block;
font-size: 16px;
padding: 10px;
}
ul li a {
text-decoration: none;
color: #222;
font-weight: bold;
padding-top: 5px;
position: relative;
}
ul li a::before,
ul li a::after {
content: '';
position: absolute;
top: -5px;
width: 50%;
height: 7px;
display: none;
}
ul li a::before {
background: #014880;
left: 0;
}
ul li a::after {
background: #1880c9;
right: 0;
}
ul li a.active,
ul li a:hover {
color: #014880;
}
ul li a.active::before,
ul li a.active::after,
ul li a:hover::after,
ul li a.list:hover::before,
ul li a.list:hover::after {
display: block
}
<ul class="h_nav_list">
<li>HOME</li>
<li>PROFILE</li>
<li>ACTIVITY</li>
</ul>
Edit: Apologies, misunderstood your question in the first go. Updated the code snippet
try JavaScript for on mouse enter and mouse leave to add style to that element
this code for your html tag :
<li>HOME</li>
make sure to add onload attribute to body tag , to load js function after page loaded like this :
<body onload="myFunction()"></body>
inside myFunction get documents you want to work with like this :
homeLink = document.getElementByID("home");
now you can work with your document element that named homeLink , inside your script.
to add style you want , fisrt create that class or just edit that style attribute like this :
homeEnter() { homeLink.style.border-top = "1px solid black" }
and to make sure style return to default do something like this :
homeLeave() { homeLink.style.border-top = '' }

My Drop Down Menu goes sideways in ie

I have a drop menu that works fine in Firefox and Chrome but not in ie. The sub menu appears underneath the main menu, but it displays sideways. How do I fix it?
The site url www.umvaonline.org
code for menu
<li class='top'><a href='blog/'>News/Blog</a>
<ul class='item'>
<li><a href='/blog/category/news/exhibition-listings/'>Exhibition Listings</a></li>
<li><a href='/blog/category/news/opportunities/'>Opportunities for Artists</a></li>
<li><a href='/blog/category/news/workshops-classes/'>Workshops & Classes</a></li>
</ul>
</li>
<li class='top'><a href='index.php?page=journal'>Quarterly Journal</a>
<ul class='item'>
<li><a href='index.php?page=submission'>Submission Guidelines</a></li>
<li><a href='/blog/category/archived-journals/'>Archived Journals</a></li>
</ul>
</li>
css
div.topnav { height:40px;margin-left:30px;margin-bottom:20px;}
div.topnav ul {z-index:10000;padding: 0 1px;
list-style: none;
position: relative;
top:0;
display: inline-table;}
div.topnav ul:after {
content: ""; clear: both; display: block;
}
div.topnav ul li {
height: 100%;
float: left;
font-family: arial, verdana, helvetica;
font-size: 95%;}
div.topnav a {
float: left;
height: 40px;
line-height: 40px;
text-align:center;
background-image: url('umva_images/umva_button.png');
padding-left:12px;
padding-right:12px;
background-repeat: repeat-x;
color: silver;
font-weight:bold;
text-shadow: 1px 1px black;
transition:color .25s ease;
text-transform:uppercase;
text-decoration:none
}
div.topnav ul.item{display:none}
div.topnav li.top:hover ul.item {display:block}
div.topnav a.left {border-top-left-radius:5px;border-bottom-left-radius:5px}
div.topnav a.right {border-top-right-radius:5px;border-bottom-right-radius:5px}
div.topnav a:hover { background-image: url('umva_images/umva_button_hover.png');color:white}
div.topnav a.current { background-image: url('umva_images/umva_button_hover.png');color:white}
div.topnav ul ul {
background: #5f6975; border-radius: 0px; padding: 0;
position: absolute; top: 100%;
box-shadow:2px 2px 5px black
}
div.topnav ul ul li {
float: none;
position: relative;
}
div.topnav ul ul li a {
background: #5f6975;
color: #fff;
font-size:90%;
width:auto;
height:25px;
line-height:25px;
text-align:left;
}
div.topnav ul ul li a:hover {
background: #5f6975;
text-decoration:underline;
}
div.topnav ul ul li a {
}
div.topnav ul li.left {border-top-left-radius:5px; border-bottom-left-radius:5px}
div.topnav ul li.right {border-top-right-radius:5px; border-bottom-right-radius:5px}
You have to check out if this is working for you - add float:none; to div.topnav ul ul li a.
Just tested in IE10 and Firefox and works for me. Though there is no float set for this element, it inherits float: left from div.topnav a.

CSS pseudo selector on drop down menu

I am using the CSS :before pseudo-selector to create a block above the first item in a drop down list. I've been having trouble getting this block created with the pseudo-selector to be the same width as the <li> above it.
For example when you hover over "About" the pseudo block that appears beneath it should be the same width as the block that contains the word "About" and so on for the other 3 blocks.
Here's a fiddle to what I have got so far: http://jsfiddle.net/jh67P/
Here's my HTML:
<nav>
<ul class="main">
<li>About
<ul class="secondary">
<li>Learn About Us</li>
<li>Nice things to know</li>
</ul>
</li>
<li>Products
<ul class="secondary">
<li>Product One</li>
<li>Product Two</li>
</ul>
</li>
<li>Features
<ul class="secondary">
<li>Something Nice</li>
<li>Another nice thing</li>
</ul>
</li>
</ul>
</nav>
Here's the CSS:
nav .main {
font-size: 1em;
margin: 0;
padding: 0;
list-style: none;
}
.main > li {
display: block;
position: relative;
float: left;
}
.main > li a {
display: block;
text-decoration: none;
color:#FFF;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #1e7c9a;
margin-left: 1px;
white-space: nowrap;
}
.main > li a:hover {
background: #3b3b3b;
color:#FFF;
}
.secondary {
display:none;
list-style: none;
margin: 0;
padding: 0;
}
.main li:hover .secondary {
display: block;
position: absolute;
}
.main li:hover ul li {
float: none;
font-size: 1em;
}
.main > li:hover a { background: #3b3b3b; }
.main > li:hover li a:hover {
background: #1e7c9a;
}
.main li:hover ul:before {
content:'';
display:block;
width:100%;
height:10px;
border-bottom:10px solid #1e7c9a;
border-right: 10px solid transparent;
}
Edit: Using absolute positioning I was able to achieve the effect. Here's the updated CSS.
nav .main {
font-size: 1em;
margin: 0;
padding: 0;
list-style: none;
}
.main > li {
display: block;
position: relative;
float: left;
}
.main > li a {
display: block;
text-decoration: none;
color:#FFF;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #1e7c9a;
margin-left: 1px;
white-space: nowrap;
}
.main > li a:hover {
background: #3b3b3b;
color:#FFF;
}
.secondary {
display:none;
list-style: none;
margin: 0;
padding: 0;
}
.main li:hover .secondary {
display: block;
position: absolute;
top:40px;
}
.main li:hover ul li {
float: none;
font-size: 1em;
}
.main > li:hover a { background: #3b3b3b; }
.main > li:hover li a:hover {
background: #1e7c9a;
}
.main > li:hover:after {
content:'';
display:block;
width:100%;
height:10px;
border-bottom:10px solid #1e7c9a;
border-right: 10px solid transparent;
position:absolute;
top:20px;
margin-left:1px;
}
How about changing:
.main li:hover ul:before {
To:
.main > li:hover > a:after {
Is that what you are after?
jsFiddle

Menu sub item hover border

In the following example - Is it possible to retain the border on the top level navigation when hovering on the sub elements? I would like to retain the black border on 'About Us' when hovering on its sub items. Example: http://jsfiddle.net/6zKRC/2/
HTML
<div class="navigation">
<ul class="navigation fc">
<li>
Home
</li>
<li class="">
About
<ul>
<li>
Sub Navigation 1
</li>
<li>
Sub Navigation 2
</li>
</ul>
</li>
</ul>
</div>​
CSS
.navigation ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
.navigation ul li {
display: block;
position: relative;
float: left;
}
.navigation li ul {
display: none;
}
.navigation ul li a {
display: block;
text-decoration: none;
color: #000;
font-weight:bold;
padding: 5px 15px 5px 15px;
white-space: nowrap;
}
.navigation ul li a:hover {
background: #CCC;
color:black;
border:solid 1px black;
border-bottom:0;
}
.navigation li:hover ul {
display: block;
position: absolute;
border:solid 1px black;
border-top:0;
}
.navigation li:hover li {
float: none;
font-size: 11px;
}
.navigation li:hover a {
background: #CCC;
}
.navigation li:hover li a:hover {
background: #CCC;
border:0;
}
​
Hi i have made some changes in your css please check your updated css :-
CSS
.navigation ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
.navigation ul li {
display: block;
position: relative;
float: left;
}
.navigation li ul {
display: none;
}
.navigation ul li a {
display: block;
text-decoration: none;
color: #000;
font-weight:bold;
padding: 5px 15px 5px 15px;
white-space: nowrap;
}
.navigation ul li:hover {
background: #CCC;
color:black;
border:solid 1px black;
border-bottom:0;
}
.navigation li:hover ul {
display: block;
position: absolute;
border:solid 1px black;
border-top:0;
left:-1px;
}
.navigation li:hover ul li {
float: none;
font-size: 11px;
background: #CCC;
}
.navigation li:hover li:hover {
background:#e6e6e6;
border:0;
}
HTML
<div class="navigation">
<ul class="navigation fc">
<li>
Home
</li>
<li class="">
About
<ul>
<li>
Sub Navigation 1
</li>
<li>
Sub Navigation 2
</li>
</ul>
</li>
</ul>
</div>​
I hope you looking this one:- http://jsbin.com/uwemuy/5/edit
change in css as follow
.navigation li:hover a {
background: #CCC;
border:solid 1px black;
}
see http://jsfiddle.net/6zKRC/2/

CSS Menu Dropdowns are all appearing under the same (left most) parent item

I have tried moving the position:relative; setting around, but to my understanding it is where it is supposed to be... Please correct me, because my understanding is clearly wrong!
<ul id="menu">
<li>All Products
<ul>
<li>Stock Lanyards</li>
<li>Screen Printed Lanyards</li>
<li>Full Color Lanyards</li>
<li>Custom Cord Lanyards</li>
<li>Specialty Lanyards</li>
</ul>
</li>
<li>Reorders</li>
<li>Resources
<ul>
<li>FAQ</li>
<li>Art Requirements</li>
<li>Production Times</li>
<li>About Us</li>
<li>Contact Us</li>
<li>Request A Sample</li>
</ul>
</li>
<li>Blog</li>
</ul>
css....
ul#menu {
margin:0px;
padding-top:20px;
position:absolute;
right:0px;
font-weight:bold;
font-size:14px;
}
ul#menu li {
display:inline;
padding-left:8px;
}
ul#menu a{
color:#8ba693;
text-decoration:none;
padding:5px;
}
ul#menu a:hover, a:active{
/* text-shadow: 0 0 0.9em #ccc;
text-decoration:underline; */
background-color:#000;
}
/* -- DROPDOWN MENU STYLES -- */
#menu ul {
margin: 0;
padding: 0;
list-style: none;
}
#menu ul li {
display: block;
position: relative;
left:0;
top:100%;
}
#menu li ul { display: none;
position: absolute;
z-index:1000;
margin:5px 0 0 0px;
top:100%;
left:0;
}
#menu ul li a {
display: block;
text-decoration: none;
padding: 7px 15px 6px 10px;
margin: 0px 0 0 0;
white-space: nowrap;
border-top: 1px solid #8ba693;
border-left: 1px solid #8ba693;
border-right: 1px solid #8ba693;
}
#menu ul li a:hover { background: #000; }
#menu li:hover > ul {
display: block;
}
#menu li:hover li {
float: none;
font-size: 11px;
}
#menu li:hover a { background: #fff; }
#menu li:hover li a:hover { background: #8ba693; color: #fff; }
ul#menu li {
display: inline;
padding-left: 8px;
position: relative;
}
http://jsfiddle.net/HFp6K/2/
position:relative needs to be in position:absolute's parent.

Resources