【问题标题】:How to align buttons (in different forms) horizontally in IE7如何在 IE7 中水平对齐按钮(以不同的形式)
【发布时间】:2013-10-20 10:59:54
【问题描述】:

我有以下包含 3 个按钮的代码:

<div id="button-panel">
    <form action="../edit/" method="GET">
     <input type="hidden" name="id" value="<?php echo $record->id; ?>" />
     <input type="submit" value="Edit" />
    </form>

    <form action="" method="POST">
     <input  type="submit" name="cancel_btn" value="Cancel" />
    </form> 

  <input type="button" id="boh-url-gen" value="Generate URL" onClick="generateURL();" />                    
</div>  <!-- button-panel -->

尽管我努力,IE7 中的按钮还是垂直对齐。目前我应用了以下 CSS:

#button-panel *{display:inline-block;}

但是,它无法在 IE7 上运行。

【问题讨论】:

    标签: html css button internet-explorer-7


    【解决方案1】:

    这仅仅是因为 IE7 不完全支持 display:inline-blockReference here.

    如果您想要完全支持,只需浮动元素即可。

    #button-panel {
        float:left; /* right */
    }
    

    注意,浮动元素会将其从流程中移除,因此您可能需要向父级添加类似 overflow:auto 的内容 - 假设内容正在折叠,因为未设置固定的 height/width

    【讨论】:

      【解决方案2】:

      IE7 不支持 display:inline-block 对默认为 block 的元素。

      相反,display:inline 让它们表现得像 inline-block(IE7 太奇怪了)

      因此,您可以使用条件 cmets 为 IE7 或 IE7 CSS hacks 创建样式表,使用 display:inline。例如:

      *:first-child+html #button-panel { /* IE7 hack which is valid CSS */
          display: inline;
      }
      

      (来自this answer Alohci 的IE7 hack)

      【讨论】:

      • 为什么display:inline 工作..?它与inline-block 元素的特性不同,因此可能无法达到预期的结果。
      • @JoshC 但是 IE7 太奇怪了,默认情况下被 display:inline 阻止的元素表现得像 display:inline-block
      • 很高兴知道,我会测试一下。
      • @JoshC 我不知道,因为我不使用不是有效 CSS 的黑客。但如果*display 是针对 IE7(但不是 IE8)的 hack,它应该可以正常工作。
      猜你喜欢
      • 1970-01-01
      • 2016-02-18
      • 2016-04-07
      • 2014-04-20
      • 1970-01-01
      • 2020-10-08
      • 1970-01-01
      • 2023-04-04
      • 2017-03-09
      相关资源
      最近更新 更多