【问题标题】:Why doesn't css work in IE when it works as expected in Firefox and Chrome?为什么 css 在 Firefox 和 Chrome 中按预期工作时不能在 IE 中工作?
【发布时间】:2017-04-29 16:24:22
【问题描述】:
    input[type=text], input[type=password], select {
        width: 100%;
        padding: 12px 20px;
        margin: 8px 0;
        display: inline-block;
        border: 1px solid #ccc;
        border-radius: 4px;
        box-sizing: border-box;
    }
    input[type=submit] {
        width: 100%;
        background-color: #808080;
        color: white;
        padding: 14px 20px;
        margin: 8px 0;
        border: none;
        border-radius: 4px;
        cursor: pointer;
    }
    input[type=submit]:hover {
        background-color: #A9A9A9;
    }
    html,body {
      height:100%;
      width:100%;
      margin:0;
    }
    body {
      display:flex;
      background-color:#D3D3D3;
    }
    form {
      margin:auto;
    }

上面的 CSS 代码使表单中心在 Chrome 和 Firefox 中对齐,但在 Internet Explorer 中不起作用。在 IE 中,表单水平居中对齐,但不是垂直居中。有什么问题以及如何使其在 IE 中正确对齐?

【问题讨论】:

  • 样式必须在头部内
  • 为什么样式应该在头部?
  • 因为是html约定w3schools.com/html/html_css.asp
  • 好的,我已将它包含在 head 部分中。仍然 css 似乎没有在 IE 中正确应用?那么有什么建议吗?
  • flex 在 IE 中只有部分支持;它在 ie10 中支持较旧的语法,并且由于存在大量错误,在 ie11 中仅支持部分语法。请参阅caniuse.com/#search=flex 这是您问题的最可能原因,但边缘应该没问题

标签: css html web forms


【解决方案1】:

上面的问题是因为 IE 只对 flex 有部分支持。

包括 align-items: center;display: flex;

之后

使 css 在 IE 中得到正确应用。

感谢 Rachel Gallen 向我指出问题在于 IE 中的 flex 支持。

参考:https://stackoverflow.com/a/17156937/5293838

cimmanon提供的解决方案:

您需要仔细阅读有关 caniuse 的说明。 “部分支持” 指支持两个较旧的草案之一,并且他们不做 注意哪个浏览器支持哪个草稿。 IE10支持三月 2012 年的选秀,它是唯一已知这样做的。

http://codepen.io/cimmanon/pen/ApHEy

 .box {
       display: -webkit-box;
       display: -moz-box;
       display: -ms-flexbox;
       display: -webkit-flex;
       display: flex;
       -webkit-box-pack: center;
       -moz-box-pack: center;
      -ms-flex-pack: center;
      -webkit-justify-content: center;
      justify-content: center;
      -webkit-box-align: center;
       -moz-box-align: center;
      -ms-flex-align: center;
       -webkit-align-items: center;
       align-items: center;
       /* fix for old FF */
       width: 100%;
     }

【讨论】:

  • 感谢我指出了这个问题,但也归功于 cimmanon [stackoverflow.com/users/1652962/cimmanon] ,写你引用的答案的用户。很好的电话,包括答案链接,但最好还是插入引用的答案副本和参考
  • 谢谢,是的,我肯定还会附上答案的引用副本:)
猜你喜欢
  • 1970-01-01
  • 2017-06-07
  • 2015-03-02
  • 1970-01-01
  • 2014-05-24
  • 2012-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多