简体   繁体   中英

Issue with css menu in internet explorer

I've been working on a css menu and it works fine in every browser besides Internet Explorer.

The issue can bee seen below: The first <li> element is not properly aligned. In fact, it's pushed down.

#sub-navigation {
    background: url("{T_THEME_PATH}/images/subnavigation.png") repeat-x;
    -webkit-border-radius: 1px;
    -moz-border-radius: 1px;
    border-radius: 1px;
    height: 25px;
    line-height: 25px;
    border-bottom: 1px solid #dfeaf1;
    border-left: 1px solid #dfeaf1;
    border-right: 1px solid #dfeaf1;
    border-top: 3px solid #ffffff;
}
#second-navigation li {
    border-right: 1px solid #cddfeb;
    padding-right: 14px;
    padding-left: 14px;
    margin-left: 0px;
    float: left;
    display: block;
    font-size: 11px;
    font-weight: none;
    font-color: #6b6b6b;
}

#second-navigation ul {
    position: absolute; 
    display: none;
    z-index: 999;
    background: #4e4e4e;
    border: none;
    border-radius: 2px;
    width: 80px;
    color: #FFFFFF;
}
<div id="sub-navigation">
        <ul id="second-navigation" class="leftside">
            <li>
                <a href="" title="Calendar"><center>Calendar</center>   </a>
            </li>
            <li>
                <a href="" title="HH Converter">HH Converter</a>
            </li>
            <li>
                <a href="" title="Poker Bonuses">Poker Bonuses</a>
            </li>
    </div>

Anyone know how to fix this, so it works in Internet Explorer.

Unfortunately, I can't test the actual code for you at the moment. Test stations are being moved around. From experience and off the top of my head -- there are a few errors.

The code:

#sub-navigation {
    background: url("{T_THEME_PATH}/images/subnavigation.png") repeat-x;
    -webkit-border-radius: 1px;
    -moz-border-radius: 1px;
    border-radius: 1px;
    height: 25px;
    line-height: 25px;
    border-bottom: 1px solid #dfeaf1;
    border-left: 1px solid #dfeaf1;
    border-right: 1px solid #dfeaf1;
    border-top: 3px solid #ffffff;
}
#second-navigation ul {
    position: absolute; 
    display: none;
    z-index: 999;
    background: #4e4e4e;
    border: none;
    border-radius: 2px;
    width: 80px;
    color: #FFFFFF;
    list-style:none;
}
#second-navigation li {
    border-right: 1px solid #cddfeb;
    padding-right: 14px;
    padding-left: 14px;
    margin-left: 0px;
    float: left;
    display: inline-block;
    font-size: 11px;
    font-weight: none;
    font-color: #6b6b6b;
    list-style-type:none;
}
#second-navigation li a {
    display:block;
}
#second-navigation .center {
    text-align:center;
}
<div id="sub-navigation">
        <ul id="second-navigation" class="leftside">
            <li>
                <a href="#" title="Calendar" class="center">Calendar</a>
            </li>
            <li>
                <a href="#" title="HH Converter">HH Converter</a>
            </li>
            <li>
                <a href="#" title="Poker Bonuses">Poker Bonuses</a>
            </li>
        </ul>
    </div>

The changes are:

  • Unless you have a reset somewhere (like YUI Reset) ul and li should include a list-style: none; and list-style-type:none;
  • On Internet Explorer, float:left; should be accompanied by display:inline-block; NOT display:block;
  • On most browsers, elements within ap and a tag, will work... IE
    usually throws a hissy fit. Use CSS to declare a text-align center... which you should be doing anyways.

Hopefully this will help!

On a side note, CSS wise... if you are wanting the links centered and what not -- get rid of all the padding & margin write ups... browsers consider padding & margins differently and could be causing the issue.

A simple:

a {
display:block;
line-height: 25px;
text-align:center;
}

Would do the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM