如何调整我的 CSS,以便 Firefox 在子标签宽度为 100% 时尊重填充?

发布于 2024-12-16 19:38:22 字数 1267 浏览 3 评论 0原文

<!DOCTYPE html>
<html>
<head>
  <style type="text/css">
    button {
      border-width: 1px;  
      border-style: solid;
      border-color: black;
      -moz-background-clip: padding-box;
      -webkit-background-clip: padding-box;
      background-clip: padding-box;
      font-family: Verdana, Geneva, sans-serif;
      font-size: 13px;
      height: 28px;
      padding: 0 10px 0 10px;
      max-width: 180px;
    }
    button > span {
      width: 100%;
      height: 100%;
      white-space: nowrap;
    }
    .text {
      max-width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
      display: inline-block;
    }
  </style>
</head>
<button>
  <span>
    <span class="icon"></span><!-- This will push the text to the right when its shown -->
    <span class="text">Button text that is really, really long</span>
  </span>
</button>
</html>

上面的代码包含一个完整的 HTML 页面,可以将其复制/粘贴到文本编辑器中并在浏览器中呈现。我这里遇到的问题是,我需要文本填充 100% 可用宽度,同时尊重左侧和右侧 10px 的填充。此处显示的 CSS 适用于最新版本的 Chrome、Safari 和 IE。然而,在 Firefox(版本 7 和 8)中,填充不被考虑。

我知道如果我删除填充并将文本宽度更改为 95%,它看起来会很相似,但我希望尽可能避免这种情况。

请告知如何针对 Firefox 进行调整并继续在其他浏览器中正常工作。感谢您抽出时间。

<!DOCTYPE html>
<html>
<head>
  <style type="text/css">
    button {
      border-width: 1px;  
      border-style: solid;
      border-color: black;
      -moz-background-clip: padding-box;
      -webkit-background-clip: padding-box;
      background-clip: padding-box;
      font-family: Verdana, Geneva, sans-serif;
      font-size: 13px;
      height: 28px;
      padding: 0 10px 0 10px;
      max-width: 180px;
    }
    button > span {
      width: 100%;
      height: 100%;
      white-space: nowrap;
    }
    .text {
      max-width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
      display: inline-block;
    }
  </style>
</head>
<button>
  <span>
    <span class="icon"></span><!-- This will push the text to the right when its shown -->
    <span class="text">Button text that is really, really long</span>
  </span>
</button>
</html>

The above code contains a full HTML page that can be copy/pasted into a text editor and rendered in your browser. The issue I have here is that I need the text to fill 100% available width while respecting the padding of 10px on the left and right side. The CSS shown here works for the latest versions of Chrome, Safari and IE. However, in Firefox (versions 7 and 8) the padding isn't being respected.

I understand that if I remove the padding and change the width of the text to 95% it will look similar but I am hoping to avoid that if possible.

Please advise on how this can be adjusted for Firefox and continue to work correctly in the other browsers. Thank you for your time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

十秒萌定你 2024-12-23 19:38:22

我不完全确定这是最好的方法,但它有效:

button::-moz-focus-inner {
    padding: 0 10px;
}

您的原始代码: http://jsbin.com/ ebinem

通过我的修复:http://jsbin.com/ebinem/2

I'm not completely sure that this is the best way, but it works:

button::-moz-focus-inner {
    padding: 0 10px;
}

Your original code: http://jsbin.com/ebinem

With my fix: http://jsbin.com/ebinem/2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文