3

I used flexbox properties to make my section look like this:

enter image description here

It works fine on Chrome but I noticed a few differences when I checked firefox and safari.

This is how chrome looks like: enter image description here

But on Firefox, I am not managing to apply to margin of 1% like I want as the red signal shows:

enter image description here

And on safari, the boxes are all one after the other:

enter image description here

It is a WordPress Site and not live yet. But here is my html structure:

    <section id="services">

        // here goes the title of the container

        <div class="main-container col-lg">  

               // here go all the box

         <div class="services-container">    

               // this one of the boxes              
         </div>
        </div>
    </section>

And the CSS:

#services {
    background-image: url("img/Services-background.jpg");
    background-color: red;
}
.col-lg {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    margin: initial;
    max-width: 100%;
}
.services-container {
    color: #d6d6d6;
    margin: 1%;
    max-width: 100%;
    width: 30%;
}

How Can I make this work on all browsers?

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
Sidney Sousa
  • 3,378
  • 11
  • 48
  • 99
  • 1
    Flexbox works fine in modern browsers. It's just new and some browsers require special attention. In this case, [**using a percentage margin is causing the problem**](http://stackoverflow.com/a/36783414/3597276). – Michael Benjamin Sep 30 '16 at 23:55
  • 1
    For Safari, see [**Chrome / Safari not filling 100% height of flex parent**](http://stackoverflow.com/q/33636796/3597276) and [**Flexbox code working on all browsers except Safari. Why?**](http://stackoverflow.com/q/35137085/3597276). – Michael Benjamin Sep 30 '16 at 23:57

4 Answers4

4

The best way to ensure that flex is working equally on all browsers is to use prefixes.

Here's the chart from MDN showing you the different browser prefixes available for flex box (and general browser support notices)

pixeldesu
  • 632
  • 6
  • 12
  • The link seems to jump around weirdly, just click on the _Browser compatibility_ link on the right sidebar to see the table with the prefixes. – pixeldesu Sep 30 '16 at 08:26
3
 display: flex;
-webkit-display: flex;
-moz-display: flex;
-ms--display: flex;
Shahzaib
  • 57
  • 4
1

I strongly suggest you not use flexbox, but floats instead. Delete all the flex properties your css should look like this:

#services{
    background-image: url(img/Services-background.jpg);
    overflow: auto;
}
.services-container {
    color: #d6d6d6;
    width: 30%;
    float: left;
    margin: 1%;
}

Then you can add the rest of the styling. It will work on all browsers.

Elton Sousa
  • 421
  • 3
  • 10
1

Sometimes the HTML version may be the reason (it was in my case):

I looked for <!DOCTYPE html> at the top of the source code. My HTML turned out to 4.0 something and that was the reason (most probably) that flex did not work. Once that was changed, it worked well.

Good luck...

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Aakash
  • 21,375
  • 7
  • 100
  • 81