我的设计是不是在Firefox和Safari一致(My design is not consiste

2019-10-23 12:13发布

继我以前的问题 ,我有一个代码来显示两行8盒。 该代码完全在Firefox和Chrome,但不是在Safari!

Firefox的输出

Safari浏览器的输出

我不知道是什么原因,可能是。

演示

<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">


<link rel="stylesheet"
  href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet"
  href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">

<style>
html, body {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
}

.itemClass {
  width: 100%;
  margin: 0 0 1em 0;
  box-shadow: 0px 0px 1px 1px black;
  background: white;
  display: flex;
}

.boxes {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  max-width: 1900px;
  width: 100%;
  margin: 0 auto;
  padding: 1em;
}

.boxesheader {
  margin: 0 auto -35px;
  max-width: 1900px;
  padding: 1em 0;
  width: 100%;
}

.itemClass>img {
  height: 74px;
  width: 120px;
  margin: 0 5px 0 0;
}

.itemClass>span {
  width: calc(100% - 55px);
  margin-left: 2%;
}

@media ( min-width :599px) {
  .itemClass {
    width: 49%;
    margin: 0 2% 1em 0;
  }
}

@media ( min-width :599px) and (max-width:1024px) {
  .itemClass:nth-child(2n + 2) {
    margin: 0 0 1em 0;
  }
}

@media ( min-width :1024px) {
  .itemClass {
    width: 24%;
    margin: 0 1.3333333333% 1em 0;
  }
  .itemClass:nth-child(4n + 4) {
    margin: 0 0 1em 0;
  }
}

</style>
</head>

<body>


<ul class="boxes">
  <li class="itemClass"><span class="content"> <strong>Adv1</strong> <br /> <a href="#"
      >XXXXXXXXXX</a>
      <p>PPPPPPPP pppppp pppppp</p>
      <p>fdfgd dfg dfgd fgda fdaf adf sdfsda fdaf df dfd fdsf sdf ds.</p>
  </span> <img
    src="http://www.google.com/images/srpr/logo11w.png"/></li>

   <li class="itemClass"><span class="content"> <strong>Adv1</strong> <br /> <a href="#"
      >XXXXXXXXXX</a>
      <p>PPPPPPPP pppppp pppppp</p>
      <p>fdfgd dfg dfgd fgda fdaf adf sdfsda fdaf df dfd fdsf sdf ds.</p>
  </span> <img
    src="http://www.google.com/images/srpr/logo11w.png"/></li>
     <li class="itemClass"><span class="content"> <strong>Adv1</strong> <br /> <a href="#"
      >XXXXXXXXXX</a>
      <p>PPPPPPPP pppppp pppppp</p>
      <p>fdfgd dfg dfgd fgda fdaf adf sdfsda fdaf df dfd fdsf sdf ds.</p>
  </span> <img
    src="http://www.google.com/images/srpr/logo11w.png"/></li>
     <li class="itemClass"><span class="content"> <strong>Adv1</strong> <br /> <a href="#"
      >XXXXXXXXXX</a>
      <p>PPPPPPPP pppppp pppppp</p>
      <p>fdfgd dfg dfgd fgda fdaf adf sdfsda fdaf df dfd fdsf sdf ds.</p>
  </span> <img
    src="http://www.google.com/images/srpr/logo11w.png"/></li>
     <li class="itemClass"><span class="content"> <strong>Adv1</strong> <br /> <a href="#"
      >XXXXXXXXXX</a>
      <p>PPPPPPPP pppppp pppppp</p>
      <p>fdfgd dfg dfgd fgda fdaf adf sdfsda fdaf df dfd fdsf sdf ds.</p>
  </span> <img
    src="http://www.google.com/images/srpr/logo11w.png"/></li>
     <li class="itemClass"><span class="content"> <strong>Adv1</strong> <br /> <a href="#"
      >XXXXXXXXXX</a>
      <p>PPPPPPPP pppppp pppppp</p>
      <p>fdfgd dfg dfgd fgda fdaf adf sdfsda fdaf df dfd fdsf sdf ds.</p>
  </span> <img
    src="http://www.google.com/images/srpr/logo11w.png"/></li>
     <li class="itemClass"><span class="content"> <strong>Adv1</strong> <br /> <a href="#"
      >XXXXXXXXXX</a>
      <p>PPPPPPPP pppppp pppppp</p>
      <p>fdfgd dfg dfgd fgda fdaf adf sdfsda fdaf df dfd fdsf sdf ds.</p>
  </span> <img
    src="http://www.google.com/images/srpr/logo11w.png"/></li>
     <li class="itemClass"><span class="content"> <strong>Adv1</strong> <br /> <a href="#"
      >XXXXXXXXXX</a>
      <p>PPPPPPPP pppppp pppppp</p>
      <p>fdfgd dfg dfgd fgda fdaf adf sdfsda fdaf df dfd fdsf sdf ds.</p>
  </span> <img
    src="http://www.google.com/images/srpr/logo11w.png"/></li>
</ul>



</body>


</html>

Answer 1:

使用前缀!

display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-wrap: wrap;
    -ms-flex-wrap: wrap;
        flex-wrap: wrap;

CanIUse是一个伟大的地方,以确认支持!
如果你能摆动它,我强烈建议工作AutoPrefixer到您的工作流程!

在样本CSS:

html, body {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
}

.itemClass {
  width: 100%;
  margin: 0 0 1em 0;
  box-shadow: 0px 0px 1px 1px black;
  background: white;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
}

.boxes {
  list-style: none;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-flex-wrap: wrap;
    -ms-flex-wrap: wrap;
        flex-wrap: wrap;
  max-width: 1900px;
  width: 100%;
  margin: 0 auto;
  padding: 1em;
}

.boxesheader {
  margin: 0 auto -35px;
  max-width: 1900px;
  padding: 1em 0;
  width: 100%;
}

.itemClass>img {
  height: 74px;
  width: 120px;
  margin: 0 5px 0 0;
}

.itemClass>span {
  width: calc(100% - 55px);
  margin-left: 2%;
}

@media ( min-width :599px) {
  .itemClass {
    width: 49%;
    margin: 0 2% 1em 0;
  }
}

@media ( min-width :599px) and (max-width:1024px) {
  .itemClass:nth-child(2n + 2) {
    margin: 0 0 1em 0;
  }
}

@media ( min-width :1024px) {
  .itemClass {
    width: 24%;
    margin: 0 1.3333333333% 1em 0;
  }
  .itemClass:nth-child(4n + 4) {
    margin: 0 0 1em 0;
  }
}

我无法解释供应商前缀任何比这里更好的答案! 所以给的是一读。
多一点信息: http://shouldiprefix.com/



Answer 2:

添加浮动:左为“.itemClass”

     .itemClass {
      float: left;
      }


文章来源: My design is not consistent in Firefox and Safari