CSS: table and table-cell replacement for IE7

你说的曾经没有我的故事 提交于 2019-12-19 10:53:04

问题


http://jsfiddle.net/vByVD/9/

This what i have. The menu looks right is horisontal in most browsers. But in IE7 and lower ofcourse it is something else, it is vertical there.

I found out this is because they dont support table, table-cell.

I tried some hacks as you can see in the first lines in the CSS, but it does not quite work, this do only show 3 li horisontal and then it makes new line and show the other li's.

I want it to appear as the other new browsers, so its one line horisontal.

How can i make this work?


回答1:


There are two ways to accomplish this. The first:

#header-nav{
    overflow: hidden;
    zoom: 1; /* IE6 and below work around */
}

#header-nav li{
    float: left;
    margin: 0;
    padding: 0;
}

#header-nav li a{
    display: block; /* if you want height and width */
    }    

The second:

#header-nav li{
    margin: 0;
    padding: 0;
    display: inline;
}

Personally I use the first of the two as it provides a bit more control for styling a block for color, width, height, margin, padding, etc. Plus, when you do a:hover the entire box is a link; not just the text. My recommendation is to not use tables. The results are unpredictable as you have seen. Not to mention, now its easier to add sub-menu's, using JQuery or CSS.



来源:https://stackoverflow.com/questions/7880854/css-table-and-table-cell-replacement-for-ie7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!