【问题标题】:Flexbox display issues on mobiles, tablets & old browsersFlexbox 在手机、平板电脑和旧浏览器上的显示问题
【发布时间】:2018-06-30 04:52:39
【问题描述】:

我希望有人能够解释这个问题。环顾互联网,令人惊讶的是,我实际上找不到这个问题的详细解决方案或解释。

我包含的代码显示了使用弹性框的工作显示。大概这个问题只发生在弹性盒子上(如果我错了,请纠正我!)。但是,如果您在旧浏览器或某些手机/平板电脑上查看此代码,则显示非常错误。

我认为添加 webkit 规则可以解决问题,但它们似乎什么也没做。

  1. 如何解决此问题?
  2. 我是否可以在某个地方看到我需要为每个 flex(和其他?)规则添加到我的网站的 -webkit 或 -moz 规则列表?

非常感谢这里的任何帮助,谢谢!

Internet Explorer 9 上的显示问题:

iPad 4 上的 Safari 显示问题:

#wrap-a {
    display: -webkit-flex;
    display: flex;
    -webkit-justify-content: space-evenly;
    justify-content: space-evenly;
    -webkit-flex-direction: row;
    flex-direction: row;
    align-items: center;
    -webkit-flex-flow: row wrap;
    flex-flow: row wrap;
}
.the-cta-top, .the-cta-bottom {
    display: block;
    font-weight: 300;
    font-size: 16px;
    color: #fff;
}
.the-cta-top a:link, .the-cta-top a:visited, .the-cta-middle a:link, .the-cta-middle a:visited, .the-cta-bottom a:link, .the-cta-bottom a:visited {
    text-decoration: none;
    color: #393939;
}
body {
  height: 1000px;
  width: 100%;
  background: lightgreen
}
.the-cta {
    box-sizing: border-box;
    width: 150px;min-width: 150px;
    height: 150px;
    border: 1px solid #fff;
    margin-top: 30px;
    -webkit-flex-direction: column;
    flex-direction: column;
    -webkit-justify-content: center;
    justify-content: center;
    align-items: center;
    display: -webkit-inline-flex;
    display: inline-flex;
    border-radius: 50%;
}
<article id="wrap-a">
            <nav onclick="location.href='#';" class="the-cta">
                <span class="the-cta-top">some</span>
                <span class="the-cta-middle"><a href="#">text</a></span>
                <span class="the-cta-bottom">here</span>
            </nav><!--
            --><nav onclick="location.href='#';" class="the-cta">
                <span class="the-cta-top">more</span>
                <span class="the-cta-middle"><a href="#">text</a></span>
                <span class="the-cta-bottom">here</span>
            </nav>
        </article>

【问题讨论】:

  • 那么它在旧浏览器上的呈现有何不同? ...在图片中会有所帮助。
  • 我没有图像,但圆圈显示在左侧,里面的所有文本都在顶部杂乱无章
  • 如果您的受众使用 IE9,您的网站应该支持它,如果不支持,那么通常会将用户重定向到看起来不错的页面,或者告诉他们需要升级浏览器的页面。关于前缀,当新属性发布时,它们使用像-webkit- 这样的前缀,这是因为它们的定义以及它们的工作方式在标准化之前经常发生变化,因此需要前缀来实现旧浏览器版本的向后兼容性。跨度>
  • 我还使用适用于 IE9 的示例更新了我的答案。

标签: html css flexbox


【解决方案1】:

IE9 不支持 Flexbox,因此您需要另一种解决方案(最后添加示例)。

当谈到 iPad4 上的 Safari(您的第二张屏幕截图)时,它的间距不正确,这是由于 space-evenly 在所有较新的浏览器上都不受支持,因此两个圆圈都向左对齐.

在下面的示例中,我使用伪元素来创建相同的效果。但请注意,如果项目开始换行,使用伪元素的这个技巧将不起作用。

堆栈sn-p

#wrap-a {
  display: -webkit-flex;
  display: flex;
  
  /*  space-evenly is not cross browser supported  */
  /*-webkit-justify-content: space-evenly;  */
  /*justify-content: space-evenly;  */

  /* combine space-between with a pseudo to acheive space-evenly  */
  -webkit-justify-content: space-between;     /*  added  */
  justify-content: space-between;             /*  added  */

  -webkit-flex-direction: row;
  flex-direction: row;
  -webkit-align-items: center;                /*  added  */
  align-items: center;
  -webkit-flex-flow: row wrap;
  flex-flow: row wrap;
}

  /* added pseudo to acheive space-evenly  */
#wrap-a::before, #wrap-a::after {
  content: '';
}

.the-cta-top,
.the-cta-bottom {
  /*display: block;                               not needed  */
  font-weight: 300;
  font-size: 16px;
  color: #fff;
}

.the-cta-top a:link,
.the-cta-top a:visited,
.the-cta-middle a:link,
.the-cta-middle a:visited,
.the-cta-bottom a:link,
.the-cta-bottom a:visited {
  text-decoration: none;
  color: #393939;
}

body {
  height: 1000px;
  /*width: 100%;                                  not needed  */
  background: lightgreen
}

.the-cta {
  box-sizing: border-box;
  width: 150px;
  min-width: 150px;
  height: 150px;
  border: 1px solid #fff;
  margin-top: 30px;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-align-items: center;                /*  added  */
  align-items: center;
  display: -webkit-inline-flex;
  display: inline-flex;
  border-radius: 50%;
}
<article id="wrap-a">
  <nav onclick="location.href='#';" class="the-cta">
    <span class="the-cta-top">some</span>
    <span class="the-cta-middle"><a href="#">text</a></span>
    <span class="the-cta-bottom">here</span>
  </nav>
  <!--
            -->
  <nav onclick="location.href='#';" class="the-cta">
    <span class="the-cta-top">more</span>
    <span class="the-cta-middle"><a href="#">text</a></span>
    <span class="the-cta-bottom">here</span>
  </nav>
</article>

已更新,版本适用于 IE9。

堆栈sn-p

#wrap-a {
}

.the-cta-top,
.the-cta-middle,
.the-cta-bottom {
  display: block;
  font-weight: 300;
  font-size: 16px;
  color: #fff;
  text-align: center;
}

.the-cta-top a:link,
.the-cta-top a:visited,
.the-cta-middle a:link,
.the-cta-middle a:visited,
.the-cta-bottom a:link,
.the-cta-bottom a:visited {
  text-decoration: none;
  color: #393939;
}

body {
  height: 1000px;
  background: lightgreen
}

.the-cta {
  display: inline-block;  
  box-sizing: border-box;
  width: 150px;
  height: 150px;
  border: 1px solid #fff;
  margin: 30px 0 0 calc( (100% - 300px) / 3);
  border-radius: 50%;
}

.the-cta > span {
  display: block;
  position: relative;
  top: 50%;
  transform: translateY(-50%)
}
<article id="wrap-a">
  <nav onclick="location.href='#';" class="the-cta">
    <span>
      <span class="the-cta-top">some</span>
      <span class="the-cta-middle"><a href="#">text</a></span>
      <span class="the-cta-bottom">here</span>
    </span>
  </nav><!--
  --><nav onclick="location.href='#';" class="the-cta">
    <span>
      <span class="the-cta-top">some</span>
      <span class="the-cta-middle"><a href="#">text</a></span>
      <span class="the-cta-bottom">here</span>
    </span>
  </nav>
</article>

【讨论】:

    猜你喜欢
    • 2013-02-03
    • 1970-01-01
    • 1970-01-01
    • 2014-09-10
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 2012-09-03
    • 1970-01-01
    相关资源
    最近更新 更多