简体   繁体   English

列表背景颜色在 IE7 中搞砸了

[英]list background colour screwed up in IE7

I've styled some unordered HTML lists and their heading to look like this in Firefox:我在 Firefox 中设置了一些无序 HTML 列表及其标题的样式:

alt text http://img24.imageshack.us/img24/711/screenshot001nij.png替代文字 http://img24.imageshack.us/img24/711/screenshot001nij.png

Unfortunately, in IE7, they look like this:不幸的是,在 IE7 中,它们看起来像这样:

alt text http://img11.imageshack.us/img11/8343/screenshot002e.png替代文字 http://img11.imageshack.us/img11/8343/screenshot002e.png

The relevant HTML is相关的 HTML 是

<div class="list-column">
    <h4>Types de pêche</h4>
    <ul>
        <li>Pêche en lac</li>
        <li>Pêche en Rivière</li>
    </ul>
</div>

And the CSS is: CSS 是:

.list-column {
  float: left;
  margin-right: 20px;
  width: 20em;
}

div.list-column h4 {
  background-color: #FDD041;
  padding: 5px !important;
}

ul li {
  background-image: url(images/arrow.gif);
  background-position: 0 11px;
  background-repeat: no-repeat;
  list-style-image: none;
  list-style-position: outside;
  list-style-type: none;
  margin-bottom: 6px;
  margin-left: -20px;
  margin-top: 2px;
  padding: 2px 0 2px 18px;
}

I suspect the fact that the div containing the list is floated left is probably the root of my problems, but I'm not sure how to workaround the poor display in IE7?我怀疑包含列表的 div 向左浮动的事实可能是我问题的根源,但我不确定如何解决 IE7 中显示不佳的问题?

Update: I tried adding a 'zoom: 1' property to the 'ul' elements to see if giving the elements 'layout' would fix the problem in IE, but it didn't.更新:我尝试向 'ul' 元素添加一个 'zoom: 1' 属性,以查看给元素 'layout' 是否可以解决 IE 中的问题,但它没有。

The problem is definitely not related to the rounded corners.问题绝对与圆角无关。 I turned them off temporarily but it didn't change anything in IE (apart from the appearance of the corners).我暂时关闭了它们,但它并没有改变 IE 中的任何东西(除了角落的外观)。

Thanks, Don谢谢,唐

IE and the other browsers have a different default style sheet. IE 和其他浏览器有不同的默认样式表。

IE indents list items by putting a 'margin-left' on the <ul>. IE 通过在 <ul> 上放置“margin-left”来缩进列表项。 The other browsers put a 'padding-left' on the <ul>.其他浏览器在 <ul> 上放置了一个'padding-left'。

So if you want to look the same in all browsers, set both 'margin-left' and 'padding-left' explicitly on <ul>.因此,如果您想在所有浏览器中看起来都一样,请在 <ul> 上显式设置 'margin-left' 和 'padding-left'。 In your case, you would want to add something like “margin: 0;在您的情况下,您需要添加类似“margin: 0; padding: 24px” on your “div.list-column ul, ul.round” rule. padding: 24px” 在你的“div.list-column ul, ul.round” 规则。

(The default list 'margin-left' in IE is, to be precise, '30pt'.) (IE 中的默认列表 'margin-left' 准确地说是 '30pt'。)

A common solution for this is setting the width of the element.一个常见的解决方案是设置元素的宽度。 This will make IE everything inside the bounds of that width.这将使 IE 的所有内容都在该宽度的范围内。

I think this is a case of IE-7 auto indending the li's the easiest way to debug this is to install IE-8;我认为这是 IE-7 自动缩进 li 最简单的调试方法是安装 IE-8; switch to compatible ie-7 mode.切换到兼容的 ie-7 模式。 then launch the developer tools from the tools menu然后从工具菜单启动开发者工具

You can then inspect the individual elements and check if there are hidden padding or margins being applied然后,您可以检查各个元素并检查是否应用了隐藏的填充或边距

I think that it can depend from different default padding on ie and firefox.我认为它可能取决于 ie 和 firefox 上的不同默认填充。 Try to use reset.css in your code if you haven't already done it.如果您还没有这样做,请尝试在您的代码中使用 reset.css。

Ps in ie8 you have developer tools which are similar to firebug. Ps 在 ie8 中你有类似于 firebug 的开发者工具。 Try to use them and see if you can't understand the issue...尝试使用它们,看看您是否无法理解问题...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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