How to display white background overflow on dropdown menu? - css

I have a drop down menu created purely with CSS. I would like to implement an overflow using z-index (i presume) that will bleed over a border on my menu to give the impression that both the link and the dropdown menu are joined.
The drop down works correctly but I need the first menu item to overflow it's white background on to the drop down menu.
If you go to http://cssdesk.com/ztK64 and hover over the first menu link you will see what I am attempting to explain.
This is my code:
CSS
/*Main nav*/
.main_nav_container{
margin: 10px 0 10px 0;
float:right;
}
ul.main_nav{
margin:0;
z-index:1;
postion:absolute;
}
ul.main_nav li{
margin:0;
display:inline-block;
border-top:solid 1px transparent;
border-left:solid 1px transparent;
border-right:solid 1px transparent;
}
ul.main_nav li a{
font-size:13px;
display:block;
font-weight:bold;
height:25px;
line-height:25px;
padding:0 13px;
text-decoration:none;
color:#1122cc;
border:1px solid transparent;
}
ul.main_nav li a:hover{
text-decoration:underline;
}
ul.main_nav li:hover{
border-top:solid 1px #ccc;
border-left:solid 1px #ccc;
border-right:solid 1px #ccc;
-moz-border-radius: 4px 4px 0 0;
border-radius: 4px 4px 0 0;
-webkit-border-radius: 4px 4px 0 0;
-khtml-border-radius: 4px 4px 0 0;
background: #fff;
}
ul.main_nav li:hover ul{
display:inline;
}
ul.main_nav li ul{
display:none;
z-index:500;
position:absolute;
background: #fff;
margin:0;
padding:0;
border:solid 1px #ccc;
-moz-border-radius: 0 4px 4px 4px;
border-radius: 0 4px 4px 4px;
-webkit-border-radius: 0 4px 4px 4px;
-khtml-border-radius: 0 4px 4px 4px;
}
ul.main_nav li ul li{
display:block;
margin:0;
padding:0;
text-align:left;
}
ul.main_nav li ul li:hover{
text-decoration:underline;
border-top:solid 1px #fff;
border-left:solid 1px #fff;
border-right:solid 1px #fff;
}
ul.main_nav li ul li a{
font-weight:normal;
}
HTML
<div class="main_nav_container">
<ul class="main_nav">
<li>
<a id="hover" href="#">For sale</a>
<ul>
<li>Property for sale</li>
<li>New homes for sale</li>
<li>Find estate agents</li>
</ul>
</li>
<li>To rent</li>
<li>New homes</li>
<li>House prices</li>
<li>Blog</li>
<li>Property advice</li>
<li>Contact</li>
</ul>
</div>

Add the following CSS:
ul.main_nav li:hover a {
border-bottom:1px solid white;
position:relative;
z-index:100;
}
ul.main_nav li:hover ul {
margin-top:-1px;
margin-left:-1px;
z-index:99;
}
You have to have the position:relative; in the a to make the z-index work correctly. The bottom border of the a is to cover up the border of the ul. The margin changes in the ul are to position the borders correctly for the effect of them being connected.

Related

submenu wont align to the menu when hovered

I'm having some problem with my menu and submenu when i hover on my menu the submenu wont align when hovered it floats on the left then show on the bottom of the first menu so when I select the last menu I cant select it. here's the reference picture.
http://prntscr.com/4trok1
HTML ( WORDPRESS )
<section class="twelve columns clearfix" style="background:transparent">
<div id="navcontainer">
<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => false, 'theme_location' => 'header-menu' ) ); ?></div>
</section>
CSS:
.menu {
width:auto;
float:left;
display:block;
}
.children {
display:none;
}
#navcontainer {
display:inline;
padding:0px;
margin: 0px; /*-8px 0 0 10px;*/
list-style:none;
position:relative;
z-index:1;
float:left;
height: 20px;
}
#navcontainer ul {
margin: 0;
padding: 0;
list-style-type: none;
text-align: left;
}
#navcontainer ul li {
display: block;
float: left;
}
#navcontainer ul li a {
text-decoration: none;
padding: .2em 1em;
color: #b37032;
background-color: #dbd2c1;
width: 100%;
}
#navcontainer ul li ul li{
display:block;
width:auto;
float: none;
background:#edebd7;
}
#navcontainer ul li ul li a {
background: transparent !important;
color: #724e32;
border-top: 0px !important;
border-left: 0px !important;
border-right: 0px !important;;
-moz-border-radius: 0 0 0 0 !important;;
-webkit-border-radius: 0 0 0 0 !important;;
border-radius: 0 0 0 0 !important;;
background-color: transparent !important;;
opacity: 1 !important;;
}
#navcontainer li:hover ul{
display:block;
}
#navcontainer ul li:hover a {
color: #724e32;
border-top: 1px solid #694b0a;
border-left: 1px solid #694b0a;
border-right: 1px solid #694b0a;
-moz-border-radius: 5px 5px 0 0;
-webkit-border-radius: 5px 5px 0 0;
border-radius: 5px 5px 0 0;
background-color: #edebd7;
opacity: 0.5;
}
#navcontainer ul li a:hover {
color: #fff;
background-color: #d3c096;
}
#navcontainer li:hover ul.children {
left:0;
top:18px;
background:#edebd7;
color:#724e32;
padding:5px;
position:absolute;
border-left:1px solid #694b0a;
border-right:1px solid #694b0a;
border-bottom:1px solid #694b0a;
white-space:nowrap;
width:160px;
height:auto;
z-index:300;
-moz-border-radius:0 0 5px 5px;
-webkit-border-radius:0 0 5px 5px;
border-radius:0 0 5px 5px;
}
#navcontainer ul li ul li:hover {
color: #fff;
background-color: #d3c096;
}
#navcontainer ul li ul li a:hover {
color: #fff;
background-color: #d3c096;
}
#navcontainer ul li ul li:hover a{
color: #fff;
background-color: transparent;
}
replace this class in your css file and everything should be fine:
#navcontainer li:hover ul.children {
top:18px;
background:#edebd7;
color:#724e32;
padding:5px;
position:absolute;
border-left:1px solid #694b0a;
border-right:1px solid #694b0a;
border-bottom:1px solid #694b0a;
white-space:nowrap;
width:160px;
height:auto;
z-index:300;
-moz-border-radius:0 0 5px 5px;
-webkit-border-radius:0 0 5px 5px;
border-radius:0 0 5px 5px;
}
the left:0 propriety was the problem. Nothing else :)

close css tooltip on touchdevises

Im creating a css only tooltip for my new website project.
This tooltip shows right on touchdevises. The only problem is that touchdevises can't close the tooltip.
How can I modify the code that touchscreen users can close the tooltip if they touch somewhere around the tooltip? Or maybe if they touch on the tooltip visible text link?
I just want to use css if possible.
The CSS that I have:
a.tooltip {outline:none;}
a.tooltip strong {line-height:30px;}
a.tooltip:hover {text-decoration:none; cursor: help;}
a.tooltip span {
z-index:10;display:none; padding:14px 20px;
margin-top:-30px; margin-left:28px;
width:220px; line-height:17px;
}
a.tooltip:hover span{
display:inline; position:absolute; color:#373535;
border:2px solid #D3D3D3; background:#fffFff;}
/*CSS3 extras*/
a.tooltip span
{
border-radius:5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-moz-box-shadow: 1px 1px 8px #CCC;
-webkit-box-shadow: 1px 1px 8px #CCC;
box-shadow: 1px 1px 8px #CCC;
}
This is the html:
Normal Text<span><strong>Tooltip title</strong><br />This would be the content of the tooltip.</span>
Thanks for help me out guys!
Regards, Dylan
I got no problems as u describet but i tryed this and it works even better on my device. So check it that helps you.
Fiddle
HTML:
<a href="#" class="tooltip">
Normal Text
</a>
<span>
<strong>Tooltip title</strong><br />
This would be the content of the tooltip.
</span>
CSS:
a.tooltip {
outline:none;
}
a.tooltip strong {
line-height:30px;
}
a.tooltip:hover {
text-decoration:none;
cursor: help;
}
span {
z-index:10;display:none;
padding:14px 20px;
margin-top:-30px;
margin-left:28px;
width:220px;
line-height:17px;
}
a.tooltip:hover + span{
display:inline; position:absolute; color:#373535;
border:2px solid #D3D3D3; background:#fffFff;}
/*CSS3 extras*/
span {
border-radius:5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-moz-box-shadow: 1px 1px 8px #CCC;
-webkit-box-shadow: 1px 1px 8px #CCC;
box-shadow: 1px 1px 8px #CCC;
}

css: block link not fitting correctly

I'm trying to create a navigation bar. What I want is when I hover to the block item it changes the background. My problem is the block is a little bigger than the link, so if I move the mouse outside the link area I can't click on it.
This is the jsfiddle I created, I changed the background color of the link when hovering over for a better visual aid
http://jsfiddle.net/Tx8MK/3/
so how can I make the link block fit the list block.
Thank you
#navBar li{
float:left;
display:block;
text-align:center;
position:relative;
padding: 4px 10px 4px 10px;
margin-right:30px;
border:none;
}
#navBar li:hover{
border: 1px solid #777777;
border-bottom:none;
padding: 3px 9px 4px 9px;
/* Background color and gradients */
background: #F4F4F4;
background: -moz-linear-gradient(top, #F4F4F4, #EEEEEE);
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#F4F4F4), to(#EEEEEE));
/* Rounded corners */
-moz-border-radius: 5px 5px 0px 0px;
-webkit-border-radius: 5px 5px 0px 0px;
border-radius: 5px 5px 0px 0px;
}
#navBar li a{
font-family:Arial, Helvetica, sans-serif;
font-size:18px;
color: #EEEEEE;
display:block;
outline:0;
text-decoration:none;
text-shadow: 1px 1px 1px #000;
padding: 0 25px;
}
#navBar li a:hover{
text-decoration: none;
color:#000;
display:block;
padding: 0 25px;
background:#fff;
}
Instead of giving the padding to the list items, give it to the anchors. Updated fiddle below:
#navBar li a{
font-family:Arial, Helvetica, sans-serif;
padding: 4px 10px 4px 10px;
-moz-border-radius: 5px 5px 0px 0px;
-webkit-border-radius: 5px 5px 0px 0px;
border-radius: 5px 5px 0px 0px;
...
}
http://jsfiddle.net/hQJye/
The problem was your padding applied to your LI. Removing that made the <a> fill your LI.
http://jsfiddle.net/Tx8MK/5/
html, body {
margin: 0;
padding: 0;
}
body {
font: 13px/22px Helvetica, Arial, sans-serif;
background: #f0f0f0;
}
nav {
position:absolute;
top:0;
width:100%;
background: #000;
color: #fff;
list-style: none;
}
nav section{
margin:10px 20px;
}
#navBar li{
float:left;
display:block;
text-align:center;
position:relative;
margin-right:30px;
border:none;
}
#navBar li:hover{
border: 1px solid #777777;
border-bottom:none;
/* Background color and gradients */
background: #F4F4F4;
background: -moz-linear-gradient(top, #F4F4F4, #EEEEEE);
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#F4F4F4), to(#EEEEEE));
/* Rounded corners */
-moz-border-radius: 5px 5px 0px 0px;
-webkit-border-radius: 5px 5px 0px 0px;
border-radius: 5px 5px 0px 0px;
}
#navBar li a{
font-family:Arial, Helvetica, sans-serif;
font-size:18px;
color: #EEEEEE;
display:block;
outline:0;
text-decoration:none;
text-shadow: 1px 1px 1px #000;
padding: 0 25px;
}
#navBar li a:hover{
text-decoration: none;
display:block;
color:#000;
background:#ff0000;
}

How to keep list item in active state whilst hovering on dropdown?

I am creating a dropdown menu on my website and have more or less completed the task successfully apart from one thing.
When hovering on the dropdown menu, the hover state of the main menu link disappears due to the fact that I am no longer hovering on it.
How can I keep the active state styling on the link whilst hovering on the dropdown items?
I have copied the code to http://cssdesk.com/PZBM2 if you hover the first list item you will see the hover state I am talking about and the dropdown.
Here is the code also:
/*Main nav*/
.main_nav_container{
margin-top:10px;
margin-bottom:10px;
display:block;
float:right;
}
ul.main_nav{
margin:0;
padding:0;
}
ul.main_nav li{
display:inline-block;
margin:0;
padding:0;
}
ul.main_nav li a{
font-size:13px;
display:block;
font-weight:bold;
position:relative;
height:25px;
line-height:25px;
padding:0 13px;
text-decoration:none;
color:#1122cc;
border:1px solid transparent;
}
ul.main_nav li a:hover{
text-decoration:underline !important;
border-top:solid 1px #ccc;
border-left:solid 1px #ccc;
border-right:solid 1px #ccc;
}
ul.main_nav li ul{
display:none;
position:absolute;
background: #fff;
margin:0;
padding:0;
border:solid 1px #ccc;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
-khtml-border-radius: 4px;
border-radius: 4px;
}
ul.main_nav li ul:hover #hover{
border:#ccc 1px solid;
}
ul.main_nav li ul li{
display:block;
margin:0;
padding:0;
text-align:left;
}
ul.main_nav li ul li a{
font-weight:normal;
}
ul.main_nav li:hover ul{
display:inline;
}
HTML
<div class="main_nav_container">
<ul class="main_nav">
<li>
<a id="hover" href="#">For sale</a>
<ul>
<li>Property for sale</li>
<li>New homes for sale</li>
<li>Find estate agents</li>
</ul>
</li>
<li>To rent</li>
<li>New homes</li>
<li>House prices</li>
<li>Blog</li>
<li>Property advice</li>
<li>Contact</li>
</ul>
</div>
you should replace
ul.main_nav li a:hover{
text-decoration:underline !important;
border-top:solid 1px #ccc;
border-left:solid 1px #ccc;
border-right:solid 1px #ccc;
}
with
ul.main_nav li:hover{
text-decoration:underline !important;
border-top:solid 1px #ccc;
border-left:solid 1px #ccc;
border-right:solid 1px #ccc;
}
in your css. Enjoy! :)

Can't Remove Border From Hyperlink IMG in Chrome or Firefox (Working in IE8)

I am using a jquery menu on a Master page, and the menu is built with a Unordered List. Inside each li, there is anchor tag. Inside this anchor tag, there is an image tag and a couple spans.
Now, the way the menu works is that you just see text (no borders or background colors) until you hover over the listitem, at which point the image and spans expode out and become visible. Everything is working great, and everything displays exactly as it should in IE8, but when I run the site in Chrome or Firefox, each listitem is displayed with a thin gray box. While this looks ok, it is not my desired effect. I assume that this is directly related to the anchor, but none of the standard CSS tricks are working. I have tried removing the anchor tag from one of the list items, and sure enough, the border is gone for that listitem. Unfortunately, I need that hyperlink there. The img tags have a src attribute, and it is defined and pulling the correct image. In the CSS (which I have in the HEAD of the site.master page, I have the following attributes set for "a", "a img", "a span":
text-decoration:none;
border-style:none;
border:none;
outline:none;
I have also tried adding border="0" directly to the IMG, but no luck at all. The only time I have seen that border disappear is when I remove the anchor tags.
I am stuck on this. Any help is greatly appreciated!
Just for ease, here is what one of the menu items looks like in code:
<ul id="sdt_menu" class="sdt_menu">
<li>
<a href="#">
<img src="images/1.jpg" border="0" alt=""/>
<span class="sdt_active"></span>
<span class="sdt_wrap">
<span class="sdt_link">the island</span>
<span class="sdt_descr">About</span>
</span>
</a>
<div class="sdt_box">
Airlines
Travel Info
Currency
</div>
</li>
And here is the Style Sheet:
ul.sdt_menu
{
position: absolute;
top: 148px;
margin:0;
padding:0;
list-style: none;
font-family:"Myriad Pro", "Trebuchet MS", sans-serif;
font-size:14px;
width:968px;
border: 0px;
}
ul.sdt_menu a{
text-decoration:none;
outline:none;
border: 0px;
}
ul.sdt_menu li{
float:left;
width:161px;
height:85px;
position:relative;
cursor:pointer;
text-decoration:none;
outline:none;
border:0px;
}
ul.sdt_menu li > a{
position:absolute;
top:0px;
left:0px;
width:161px;
height:85px;
z-index:12;
-moz-box-shadow:0px 0px 2px #000 inset;
-webkit-box-shadow:0px 0px 2px #000 inset;
box-shadow:0px 0px 2px #000 inset;
text-decoration:none;
outline:none;
border:0px;
}
ul.sdt_menu li a img{
border:none;
text-decoration:none;
outline:none;
position:absolute;
width:0px;
height:0px;
bottom:0px;
left:85px;
z-index:100;
-moz-box-shadow:0px 0px 4px #000;
-webkit-box-shadow:0px 0px 4px #000;
box-shadow:0px 0px 4px #000;
}
ul.sdt_menu li span.sdt_wrap{
position:absolute;
top:25px;
left:0px;
width:161px;
height:60px;
z-index:15;
border:none;
text-decoration:none;
outline:none;
}
ul.sdt_menu li span.sdt_active{
position:absolute;
background:#111;
top:85px;
width:161px;
height:0px;
left:0px;
z-index:14;
-moz-box-shadow:0px 0px 4px #000 inset;
-webkit-box-shadow:0px 0px 4px #000 inset;
box-shadow:0px 0px 4px #000 inset;
border:none;
text-decoration:none;
outline:none;
}
ul.sdt_menu li span span.sdt_link,
ul.sdt_menu li span span.sdt_descr,
ul.sdt_menu li div.sdt_box a{
margin-left:15px;
text-transform:uppercase;
text-decoration:none;
outline:none;
border:none;
}
ul.sdt_menu li span span.sdt_link{
color:#333333;
font-size:24px;
float:left;
clear:both;
text-decoration:none;
outline:none;
border:none;
}
ul.sdt_menu li span span.sdt_descr{
color:#0066FF;
float:left;
clear:both;
width:155px; /*For dumbass IE7*/
font-size:12px;
letter-spacing:1px;
text-decoration:none;
outline:none;
border:none;
}
ul.sdt_menu li div.sdt_box{
display:block;
position:absolute;
width:161px;
overflow:hidden;
height:161px;
top:85px;
left:0px;
display:none;
background:#000;
z-index:100;
text-decoration:none;
outline:none;
border:none;
}
ul.sdt_menu li div.sdt_box a{
float:left;
clear:both;
line-height:30px;
color:#0066FF;
text-decoration:none;
outline:none;
border:none;
}
ul.sdt_menu li div.sdt_box a:first-child{
margin-top:5px;
}
ul.sdt_menu li div.sdt_box a:hover{
color:#666666;
}
Thanks for posting the stylesheet. That gray "border" you're seeing is from this rule:
ul.sdt_menu li > a {
-moz-box-shadow:0px 0px 2px #000 inset;
-webkit-box-shadow:0px 0px 2px #000 inset;
box-shadow:0px 0px 2px #000 inset;
}
According to http://msdn.microsoft.com/en-us/library/cc351024%28v=vs.85%29.aspx IE didn't add box-shadow support until IE9, which is why you don't see the shadow in IE8.

Resources