CSS drop-down menu explosion in Internet Explorer 7 - html

I am creating a design with a drop-down menu and everything works well in modern browsers (i.e. Firefox, Chrome, Opera, Safari, and IE9). However, due to to the number of visitors using IE7 and IE8, I also need to make the menu compatible with those versions of Internet Explorer.
Here is the drop-down menu (fiddle, pastebin):
HTML
<ul class="menu_top">
<li>Home</li>
<li>Help Videos<ul>
<li>Child Page</li>
<li>Site Map<ul>
<li>Galleries</li>
<li>Missing</li></ul>
</li></ul>
</li>
<li>About<ul>
<li>Contact</li></ul>
</li>
</ul>
CSS
ul.menu_top {
float:left;
width:70%;
margin: 8px 100px 0 0;
border-radius:4px;
background-color: #c4092a;
list-style-type: none;
z-index:+1;
}
ul.menu_top li {
float: left;
position: relative;
margin: 4px 2em 4px 4px;
padding: 0;
}
ul.menu_top li ul {
visibility: hidden;
position: absolute;
top:100%;
left:0;
padding:0.5em;
list-style-type: none;
white-space:nowrap;
background-color: #c4092a;
border: 1px solid white;
border-radius:4px;
z-index:+1;
}
ul.menu_top li:hover > ul {
visibility: visible;
z-index: +2;
}
ul.menu_top li ul li {
padding: 0;
margin: 12px 4px;
float:none;
border:0;
min-width:3em;
}
ul.menu_top li ul li ul {
top:0;
left:99%;
}
ul.menu_top a {
background-color:#c4092a;
color:white;
text-decoration:none;
padding:4px;
font-size:18px
}
ul.menu_top a:hover,
ul.menu_top a.haschildren.childselected,
ul.menu_top a.selected {
background-color:white;
color:blue;
text-decoration:none;
}
ul.menu_top li a.haschildren:after {
content: "\00A0\00A0\25BC";
}
a {
color:#0000aa;
background-color:inherit;
}
Screenshot in IE7 and IE8
I have tested the backward compatibility in IE Developer Tools:
IE7: The <ul> lists are displaced and navigation is impossible
IE8: Only missing round corners (this is a minor problem)
I tried to modify the style as advised in this answer, but not successfully.
So, does anybody have any idea how to fix these issues?

Overall, your issue is that the CSS you are using is more advanced than some of the browsers you need to support. Rounded corners and most pseudo elements have spotty support in older browsers.
I noticed that your arrow is missing in IE7, that was my clue. IE7 does not support the pseudo-class element :after. Here is a helpful reference page to check on browser support of certain CSS http://kimblim.dk/css-tests/selectors/.
Quirksmode.org is a good resource for compatibility. Here is there page specific to :after http://www.quirksmode.org/css/beforeafter.html

Related

Navigation bar with drop down not working

I'm doin' a navigation bar for a website. I created it etc. but when I go to one of the sub menu's it disappears..
here's my HTML:
<ul id="menu">
<li>Welcome</li>
<li>Review
<ul>
<li>Customer Reviews</li>
<li>Leave a Review</li>
</ul>
</li>
<li>Gallery</li>
<li>Discounts
<ul>
<li>Refer us!</li>
<li>Claim discount</li>
</ul>
</li>
<li>Send me an email!
</li>
</ul>
</nav>
and my CSS:
/* nav */
nav{
text-align:center;
}
nav a:visited{
color:black;
}
nav a{
text-decoration:none;
color:black;
}
#menu {
margin:0 auto;
display: inline-block;
list-style-type:none;
padding:0;
}
#menu li {
float: left;
position: relative;
list-style-type: none;
background:white;
border:1px solid black;
margin-left:10px;
margin-top:5px;
border-radius:4px;
}
#menu li a {
font-family:helvetica;
display:block;
padding:10px 10px;
text-decoration:none;
}
#menu li a:hover {
color:orange;
}
#menu li ul {
background: none repeat scroll 0 0 #ffffff;
margin-top:6px;
margin-right:1px;
padding: 2px;
}
/*#menu, #menu ul {
margin:0 auto;
padding: 0;
}*/
#menu li {
float: left;
position: relative;
list-style-type: none;
}
#menu > li:hover > ul {
display: block;
}
#menu > li > ul {
display: none;
position: absolute;
}
#menu li a {
white-space: nowrap;
}
and a little JSFiddle for ya: http://jsfiddle.net/nv741s01/
If you hover your mouse over a menu option [that has a sub-menu] long enough and then do it, it works, but people won't be willing to wait three seconds every time they want to visit a sub menu, so how do I resolve it so that it works as soon as you go to it?
any help would be much appreciated, thanks in advance :)
It was because there was a little gap between the sub menu and the menu, here is the fixed JSFiddle:
http://jsfiddle.net/nv741s01/3/
And here is what I changed:
#menu li ul {
background: none repeat scroll 0 0 #ffffff;
margin-top: 1px;
margin-right:1px;
padding: 2px;
}
I changed the margin-top to 1px.
The margin of an element doesn't capture hover events. Use padding instead. Make these changes:
#menu li {
float: left;
position: relative;
list-style-type: none;
background:white;
padding-left:10px;
padding-top:5px;
margin:0;
}
/* add this rule */
#menu li a {
border:1px solid black;
border-radius:4px;
}
#menu li ul {
background: none repeat scroll 0 0 #ffffff;
margin-top:0px;
margin-right:1px;
padding: 2px;
}
Fiddle: http://jsfiddle.net/nv741s01/2/
You are using margin to position the submenu away from the main item. Since margin isn't part of the actual element it doesn't trigger any hover behaviours. Instead, use padding on the child ul element, since padding is actually considered part of the child's box. This will make the hover behaviours trigger consistently when moving the mouse from parent to child.
You also describe that there's a 3 second delay somewhere - that's impossible from this code, and I cannot reproduce it obviously.
Your dropdowns are disappearing because as you move your mouse cursor down, there's a gap between the parent menu item and the child menu item.
When the mouse leaves the parent li space, it no longer applies to the hover state, and so the CSS rule is ignored, leaving the child menu hidden.
If it helps, I tend to use a combination of margins and padding, to 'bump together' the parent and child menus, to help navigation.

CSS 'position:relative;' and 'top:xx%;' tag combo work in chrome but not in any non-webkit browser (FF, IE, Opera, etc)

I have come across a very peculiar behavior especially for what I consider to be a simple piece of code! Basically, I am trying to 'position:relative;' a footer navigation at the bottom of my page. In chrome it is correctly in the bottom. In FF (or any other non-webkit browser) it isn't at the bottom and almost at the top of the page. If I change ONE CSS line (position:relative to position:absolute;) it works for all browsers but it doesn't float correctly as I resize the screen or zoom in/out. I have confirmed this in 'boiler plate' HTML/CSS and with all the proper browser(s) resets as well and am getting the same behavior. This is all in Windows 7. Below are two very short snippets of HTML and CSS. Why isn't this working? Any solutions on how I can get a simple footer navigation to work across browsers AND have it float correctly as I zoom in/out will be greatly appreciated!
<ul id="avmenu">
<li class="current">First page</li>
<li>Second page</li>
<li>Third page</li>
<li>Fourth page</li>
<li>Fifth page</li>
</ul>
ul#avmenu {
margin: 35px 0;
padding: 0;
font: 12px Verdana;
list-style-type: none;
position:relative; <---As is this works in chrome only. JUST CHANGE THIS to position:absolute and it works in all browsers but it doesn't float well resizing or zooming.
top:70%; <--This only works ONLY in CHROME when above position:relative. Work improperly whhn position: absolute.
*left:20%;
}
ul#avmenu li {
display: inline;
}
ul#avmenu li a {
padding: 5px 10px;
border: 1px solid #aaa;
background-color: #eee;
color: #47a;
text-decoration: none;
}
See if this helps you: http://jsfiddle.net/panchroma/u9qtd/
To make this happen you will see I've forced the body to be full height. Depending on the specifics of what wraps around the UL on your actual page, you might need to adjust this.
As for the details of relative vs absolute, I can't improve on this discussion: Position Relative vs Position Absolute?
CSS
html, body {
height: 100%;
}
ul#avmenu {
margin: 35px 0;
padding: 0;
font: 12px Verdana;
list-style-type: none;
position:relative;
top:70%;
left:20%;
}
ul#avmenu li {
display: inline;
}
ul#avmenu li a {
padding: 5px 10px;
border: 1px solid #aaa;
background-color: #eee;
color: #47a;
text-decoration: none;
}

Horizontal menu bar with horizontal sub menu does not working in IE

I use the following HTML program for creating Horizontal menu bar with horizontal sub menu.It was working fine in Fire Fox and Chrome but it doesn't work in IE.So What are the changes are need changes in this program?
<html>
<head>
<style>
/* Targeting both first and second level menus */
#nav li {
list-style:none;
float: left;
position: relative;
}
#nav li a {
display: block;
padding: 8px 12px;
text-decoration: none;
}
#nav li a:hover {
background-color:red;
color:#FFF;
opacity:1;
}
/* Targeting the first level menu */
#nav {
top:150px;
min-width:850px;
background:#fff;
opacity:0.5;
display: block;
height: 34px;
z-index: 100;
position: absolute;
}
#nav > li > a {
}
/* Targeting the second level menu */
#nav li ul {
color: #333;
display: none;
position: absolute;
width:850px;
}
#nav li ul li {
display: inline;
}
#nav li ul li a {
background: #fff;
border: none;
line-height: 34px;
margin: 0;
padding: 0 8px 0 10px;
}
#nav li ul li a:hover {
background-color:red;
color:#FFF;
opacity:1;
}
/* Third level menu */
#nav li ul li ul{
top: 0;
}
ul.child {
background-color:#FFF;
}
/* A class of current will be added via jQuery */
#nav li.current > a {
background: #f7f7f7;
float:left;
}
/* CSS fallback */
#nav li:hover > ul.child {
left:0;
top:34px;
display:inline;
position:absolute;
text-align:left;
}
#nav li:hover > ul.grandchild {
display:block;
}
</style>
</head>
<body>
<ul id="nav">
<li>Home</li>
<li>
Products
<ul class="child">
<li>Hard Drives</li>
<li>Monitors</li>
<li>Speakers
<ul class="child">
<li>10 watt</li>
<li>20 watt</li>
<li>30 watt</li>
</ul>
</li>
<li>Random Equipment</li>
</ul>
</li>
<li>
Services
<ul class="child">
<li>Repairs</li>
<li>Installations</li>
<li>Setups</li>
</ul>
</li>
<li>About</li>
<li>Contact</li>
</ul>
</body>
</html>
do you use modernizr? or have available classes for legacy IE browsers? You might want to try messing with separate styles and/or stylesheets for IE.
Or
You can switch your navigation from floated blocks to "inline" elements, which older browsers such as IE6 that don't work well with floats will recognize.
Or
If you want to stick with floats then make sure you are setting a "width" for any floated element.
Chris Coyier has a nice article on floats that contains a section labeled: "Problems with Floats"
http://css-tricks.com/all-about-floats/
Well for some reason I can't even get the fiddle site to work at all in IE8...? But one problem I noticed in your CSS, is opacity. IE8 doesn't support the opacity property. To change the opaqueness of elements in old IE, use filter:alpha(opacity=75); Note, the value 75 is a whole number from 1 to 100, not a decimal like with the opacity property. I wish I could be more help, but I can't even see what the problem is in the fiddle...

CSS: Horizontal Tabs Displaying Vertically in IE6 and Firefox

I have some CSS and HTML for horizontal tabs that works perfectly in jsfiddle. However, in both Firefox 13 and IE6 (the browser I most need this to work in) the tabs are displayed as a vertical unordered list.
Here is the CSS:
.tablist
{
list-style:none;
height:2em;
padding:0;
margin:0;
border: none;
}
.tablist li
{
display:inline-block;
float: left;
}
.tablist li a
{
float: left;
margin-right:0.13em;
padding:0 1em;
text-decoration:none;
border:0.06em solid #000;
border-bottom:0;
font:bold 0.88em/2em arial,geneva,helvetica,sans-serif;
color:#000;
background-color:#ccc;
/* CSS 3 elements */
webkit-border-top-right-radius:0.50em;
-webkit-border-top-left-radius:0.50em;
-moz-border-radius-topright:0.50em;
-moz-border-radius-topleft:0.50em;
border-top-right-radius:0.50em;
border-top-left-radius:0.50em;
}
.tablist li a:hover
{
background:#3cf;
color:#fff;
text-decoration:none;
}
.tablist li#current a
{
background-color: #777;
color: #fff;
}
.tablist li#current a:hover
{
background: #39C;
}
And here is the HTML:
<div class="tablist">
<ul>
<li><strong>Tutorialsphere</strong></li>
<li><strong>Photoshop</strong></li>
<li><strong>Illustrator</strong></li>
<li><strong>Fireworks</strong></li>
<li><strong>Flash</strong></li>
<li><strong>CSS</strong></li>
<li><strong>PHP</strong></li>
</ul>
</div>
For a while this was working in Firefox and I don't remember changing anything -- but I must have.
Any advice is appreciated.
Regards.
IE6 doesn't support inline-block. As such, it's just ignoring your display property and leaving it at its default.
I don't have IE6 handy, but try display: block; float:left to this selector: .tablist li a

CSS vertically aligned anchor inside li - IE8/IE9 issue

I've recently come across a nasty issue in IE8/IE9 (surprisingly, it aligns at it should in IE7). Please check out http://targettedmedia.co.uk/httpdocs
As you can see in Firefox/Chrome or other modern browser, on hover over the top menu, the submenu items should be vertically centered (regardless of one or 2-lined items). Yet, in IE8 and IE9 it just doesn't want to work. I've tried editing the code but to no avail.
Can you please help me? It's just getting too frustrating to handle it. I sincerely thank you in advance!
Here's a sample HTML sub-menu structure:
<ul id="nav" class="dropdown dropdown-horizontal">
<li>Health & Safety Courses
<ul class="sub-menu">
<li>NEBOSH National Diploma</li>
<li>NEBOSH Construction Certificate</li>
<li>NEBOSH Fire Certificate</li>
<li>NEBOSH Distance Learning Couse</li>
<li>IOSH Managing Safely</li>
<li>IOSH Working Safely</li>
<li>Site Managers Safety Training Scheme</li>
<li>Health & Safety Awareness for Employees</li>
<li>Health & Safety Awareness for Managers</li>
</ul>
</li>
</ul>
Here are the specific CSS bits that handle the vertical alignment:
ul.dropdown ul {
width:400px;
padding:20px 0 25px 7px;
background:#6c6c6c;
font-size:14px;
font-weight:normal;
}
ul.dropdown ul li {
font-weight: normal;
height:42px;
line-height:42px;
float:left;
margin:0 0 0 15px;
border-top:1px solid #484848;
}
ul.dropdown ul li a:link {
display:inline-block;
width:165px;
padding:0;
color:#fff;
text-align:left;
line-height:normal;
vertical-align:middle;
}
Avoid depending vertical-align: middle as it's not supported in many browsers. Instead, remove all your padding and margins from ul.dropdown ul li a:link and add padding to the <li> itself. If you add equal padding to the top and bottom (I would also do padding in em, that way the padding ratio looks the same no matter what size your user has their text set to) it will be equal all around.
ul.dropdown ul li {
border-top: 1px solid #484848;
float: left;
font-weight: normal;
height: 2em;
margin: 0 0 0 15px;
padding: 1em 0;
}
ul.dropdown ul li a {
color: #FFFFFF;
padding: 0;
text-align: left;
width: 165px;
}