html <button> 标签在 Firefox 中呈现奇怪

标签 html firefox button alignment

我有以下代码,基本上显示 <button> , 和按钮里面的两个 <div> s,一个在按钮的左上角对齐,另一个在右下角对齐:

<html>
  <head>
    <style>
      <!--
      .button {
      width: 300px;
      height: 200px;
      background-color: yellow;
      position: relative;
      padding: 0px;
      }

      .child_top_left {
      position: absolute;
      top: 5px;
      left: 5px;
      background-color: blue;
      }

      .child_bottom_right {
      position: absolute;
      bottom: 5px;
      right: 5px;
      background-color: red;
      }
    -->
    </style>
  </head>
  <body>
    <button class="button">
      <div class="child_top_left">top-left</div>
      <div class="child_bottom_right">bottom-right</div>
    </button>
  </body>
</html>

在 Internet Explorer 或 Safari 中一切正常,但在 Firefox 中显示异常。看起来 Firefox 认为按钮的“顶部”实际上位于按钮的中间。

有人遇到过这种行为吗?也许有一些解决方法?

谢谢。

最佳答案

不确定是否已在 DocType 上回答了这个问题,但我设法在 Firefox 中找到了一个简单的解决方法;我没有要测试的 IE 实例,但基本上,您只需将按钮内容包装在一个 div 中:

<html>
  <head>
    <style>
      <!--
      .button {
      width: 300px;
      height: 200px;
      background-color: yellow;
      position: relative;
      padding: 0px;
      }

      .child_top_left {
      position: absolute;
      top: 5px;
      left: 5px;
      background-color: blue;
      }

      .child_bottom_right {
      position: absolute;
      bottom: 5px;
      right: 5px;
      background-color: red;
      }

      .button_container {
          width: 300px;
          height: 200px;
      }
    -->
    </style>
  </head>
  <body>
    <button class="button">
      <div class="button_container">
          <div class="child_top_left">top-left</div>
          <div class="child_bottom_right">bottom-right</div>
      </div>
    </button>
  </body>
</html>

关于html <button> 标签在 Firefox 中呈现奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2192776/

相关文章:

html - div 移动下面的其他 div

Firefox2 显示 : inline-block hack with position: relative not working

javascript - 输入搜索在 Edge、IE 或 Firefox 中不起作用

javascript - FireFox 扩展中的临时存储

css - WordPress 中的按钮

grails - 如何在带有if-else语句的grails中使用提交按钮?

javascript - 如何在 AJAX 调用中添加 loading.. 消息?

javascript - 背景图像缩放到屏幕大小而不是内容

html - 使用魔术棒坐标的图像 map 软件

php - 如何从 HTML 按钮单击调用类中的 PHP 函数