1

Following my previous question, I have a code to show 8 boxes in two rows. The code perfectly works in FireFox and Chrome but not in Safari!

Firefox's output

enter image description here

Safari's output

enter image description here I have no clue what the reason might be.

Demo

Code

<!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>
Community
  • 1
  • 1
Jack
  • 6,430
  • 27
  • 80
  • 151

2 Answers2

1

Use the prefixes!

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

CanIUse is a great spot to confirm support!
And if you can swing it, I highly recommend working AutoPrefixer into your workflow!

IN THE SAMPLE 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;
  }
}

I couldn't explain vendor prefixes any better than the answer here! So give that a read.
And a little more information: http://shouldiprefix.com/

Community
  • 1
  • 1
Jason Lydon
  • 7,074
  • 1
  • 35
  • 43
  • Thanks for your answer, I am quite confused where should I use these? which parts of code should be changed? whats your idea about Ezhil_UI-Developer's answer? – Jack Jun 24 '15 at 23:28
0

Add float:left to ".itemClass"

     .itemClass {
      float: left;
      }
ItzMe_Ezhil
  • 1,276
  • 2
  • 11
  • 22
  • It works thanks would you tell me the reasoning behind this. – Jack Jun 24 '15 at 05:52
  • Because in safari ".itemClass" occupy full width of the sceen . if u adds flot:left. it will occupy the correct width. – ItzMe_Ezhil Jun 24 '15 at 06:18
  • I see why it does not occupy full width of the screen in firefox? – Jack Jun 24 '15 at 06:26
  • This works because `display:flex` needs prefixes (-webkit) for Safari as well as IE. So `flex` isn't working on Safari as the CSS stands. When you add the `float:left`, it's then applying a rule and approach to horizontal lists. Nothing wrong with it, just a different approach. If you commit to using float, then you should remove any mention of `flex` and `flex-wrap`. – Jason Lydon Jun 24 '15 at 15:26