浮动图像在 ol 的 li 内,文本在左,适用于 Chrome,不适用于 IE/FF
我想要一个有序列表,其中左侧有文本,右侧有每个 li 的图像。 所以我将图像向右浮动,它正确地将图像放在右侧,将文本放在左侧,但图像在 IE 和 FF 中太低了 14 像素。 Chrome 做得对。 在我看来,IE 和 FF 将浮动放在每个 LI 的外部或下方,而不是应在的内部(如 Chrome)。 如果我将 IE 和 FF 的位置调整为 -14px(向上),它们工作正常,但 Chrome 就混乱了。 14px 是每个 LI 的高度,这就是这个技巧起作用的原因。
除非绝对需要,否则我不希望对浏览器进行黑客攻击(即,为 IE/FF 执行 -14px 偏移并告诉 Chrome 忽略它)。
#top25list{
width:185px;
cursor:n-resize;
list-style:
decimal inside;
padding:0;
margin:0
}
#top25list li{
margin:0;
padding:0 3px;
background-color:#FFF;
border-top:1px solid #990100;
border-bottom:1px solid #990100
}
#top25list img{
border:none;
height:13px;
width:13px;
float:right
}
#top25list li:hover{
background-color:#990100;
color:#FFF
}
li 没有什么特别的:
<li id=##>Name <a href="#" rel="##" class="removeTeam"><img src="/images/button-x.png" alt="Remove Name"></a></li>
请参阅第一个 LI 没有 FF/IE 的图像,因为它位于下方(看起来像是 #2 的图像),而 #25 图像不在列表的底部。
我希望这 3 个产品看起来都像 Chrome。 有一些 JavaScript 生成 OL/LI,而 class=removeTeam
仅适用于 jQuery 操作。 该列表位于 jQuery 可排序中,并且我确实使用 jQuery 禁用了列表选择(.disableSelection();
)。 我不认为这与 jQuery 或 JavaScript 有任何关系,只是简单的 CSS。
I would like to have an ordered list that has the text on the left and an image for each li within it on the right of the li. So I floated the image to the right and it puts the image correctly on the right and text on the left, but the image is 14 pixels too low in IE and FF. Chrome does it right. This appears to me to be IE and FF putting the float outside or underneath each LI instead of inside where it should be (like Chrome). If I adjust the position -14px (up) for IE and FF, it works fine for them, but then Chrome is messed up. 14px is the height of each LI which is why that trick works.
I don't want a single browser hack unless absolutely needed (ie, do the -14px offset for IE/FF and tell Chrome to ignore it).
#top25list{
width:185px;
cursor:n-resize;
list-style:
decimal inside;
padding:0;
margin:0
}
#top25list li{
margin:0;
padding:0 3px;
background-color:#FFF;
border-top:1px solid #990100;
border-bottom:1px solid #990100
}
#top25list img{
border:none;
height:13px;
width:13px;
float:right
}
#top25list li:hover{
background-color:#990100;
color:#FFF
}
Nothing special about the li's:
<li id=##>Name <a href="#" rel="##" class="removeTeam"><img src="/images/button-x.png" alt="Remove Name"></a></li>
See the first LI doesn't have the image for FF/IE because it's below (where it looks like it's for #2) and the #25 image is off the bottom of the list.
I want all 3 to look like the Chrome. There is some JavaScript producing the OL/LIs, and the class=removeTeam
is just for jQuery actions. This list is within a jQuery sortable and I do have the list selection disabled with jQuery (.disableSelection();
). I don't think this has anything to do with jQuery or JavaScript, just simple CSS.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是 IE 和 Firefox 共有的错误。 要解决此问题,您必须将图像移动到其行中任何非浮动文本之前。
It's a bug that IE and Firefox share. To work around it you must move image to be before any non-floated text in its line.
如果您无法更改 HTML,您可以尝试定位而不是浮动。
我没有测试过,如果我错了请告诉我。
If you can't change the HTML you could try positioning instead of floats.
I haven't tested this, let me know if I'm wrong.
列表样式:里面把它弄乱了。
下面是有效的代码。 我将浮动移至 #top25list a 并将 移至名称之前。
The list-style: inside is messing it up.
Below is the code that works. I moved the float to the #top25list a and moved the to before the name.