浮动图像在 ol 的 li 内,文本在左,适用于 Chrome,不适用于 IE/FF

发布于 2024-07-21 08:13:35 字数 1310 浏览 6 评论 0原文

我想要一个有序列表,其中左侧有文本,右侧有每个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

东走西顾 2024-07-28 08:13:35

这是 IE 和 Firefox 共有的错误。 要解决此问题,您必须将图像移动到其行中任何非浮动文本之前。

<li id=##>
   <a href="#" rel="##" class="removeTeam">
      <img src="/images/button-x.png" alt="Remove Name">
   </a> 

   Name
</li>

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.

<li id=##>
   <a href="#" rel="##" class="removeTeam">
      <img src="/images/button-x.png" alt="Remove Name">
   </a> 

   Name
</li>
滴情不沾 2024-07-28 08:13:35

如果您无法更改 HTML,您可以尝试定位而不是浮动。


#top25list li{
  margin:0;
  padding:0 3px 10px 3px; /* add padding-right to make room for the image */
  background-color:#FFF;
  border-top:1px solid #990100;
  border-bottom:1px solid #990100;
  position: relative; /* for img to have position  */
}

#top25list img{
  border:none;
  height:13px;
  width:13px;
  position: absolute;
  top: 0;  
  right: 0; 
}

我没有测试过,如果我错了请告诉我。

If you can't change the HTML you could try positioning instead of floats.


#top25list li{
  margin:0;
  padding:0 3px 10px 3px; /* add padding-right to make room for the image */
  background-color:#FFF;
  border-top:1px solid #990100;
  border-bottom:1px solid #990100;
  position: relative; /* for img to have position  */
}

#top25list img{
  border:none;
  height:13px;
  width:13px;
  position: absolute;
  top: 0;  
  right: 0; 
}

I haven't tested this, let me know if I'm wrong.

屋檐 2024-07-28 08:13:35

列表样式:里面把它弄乱了。

下面是有效的代码。 我将浮动移至 #top25list a 并将 移至名称之前。

#top25list{
       width:185px;
       cursor:n-resize;
       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 a{float:right;}
#top25list img{
       border:none;
       height:13px;
       width:13px;
}
#top25list li:hover{
       background-color:#990100;
       color:#FFF
}

<ul id="top25list">
    <li><a href="#" rel="##" class="removeTeam"><img src="/images/button-x.png" alt="Remove Name"></a>Name </li>
    <li><a href="#" rel="##" class="removeTeam"><img src="/images/button-x.png" alt="Remove Name"></a>Name </li>
    <li><a href="#" rel="##" class="removeTeam"><img src="/images/button-x.png" alt="Remove Name"></a>Name </li>
    <li><a href="#" rel="##" class="removeTeam"><img src="/images/button-x.png" alt="Remove Name"></a>Name </li>
</ul>

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.

#top25list{
       width:185px;
       cursor:n-resize;
       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 a{float:right;}
#top25list img{
       border:none;
       height:13px;
       width:13px;
}
#top25list li:hover{
       background-color:#990100;
       color:#FFF
}

<ul id="top25list">
    <li><a href="#" rel="##" class="removeTeam"><img src="/images/button-x.png" alt="Remove Name"></a>Name </li>
    <li><a href="#" rel="##" class="removeTeam"><img src="/images/button-x.png" alt="Remove Name"></a>Name </li>
    <li><a href="#" rel="##" class="removeTeam"><img src="/images/button-x.png" alt="Remove Name"></a>Name </li>
    <li><a href="#" rel="##" class="removeTeam"><img src="/images/button-x.png" alt="Remove Name"></a>Name </li>
</ul>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文