Safari's flexbox wraps the final column on the top row

When viewed in Safari and some other iOS based browsers, the last column of the first row wraps to the next line.

Safari:

https://i.sstatic.net/FhYyn.jpg

Chrome / Others:

https://i.sstatic.net/Vkvr0.jpg

Code:

.flexthis {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-flex-wrap: wrap;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
}

.flexthis .col-md-4 {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
}
<div class="row flexthis">
  <div class="col-md-4 col-sm-6 text-center">
    <div class="product">
      <img src="img.jpg" alt="" class="img-responsive">
      <h3>Name</h3>
      <p>Description</p>
    </div>
  </div>
</div>

Answer №1

Reasoning

The issue arises because Safari interprets :before and :after pseudo-elements as actual elements, affecting the layout. For example, consider a container with 7 items. When incorporating :before and :after, Safari arranges the items in the following manner:

[:before ] [1st-item] [2nd-item]

[3rd-item] [4th-item] [5th-item]

[6th-item] [7th-item] [:after  ]

Resolution

In contrast to the solution proposed earlier, I opt to eliminate :before & :after from flex containers rather than modifying the HTML structure directly. In this case, execute the following code:

.flexthis.container:before,
.flexthis.container:after,
.flexthis.row:before,
.flexthis.row:after {
   content: normal; // `initial` not supported by IE
}

Answer №2

Just wanted to provide an update on my query.

I have decided to implement the following solution, specifically tailored for Bootstrap3 as it is not flexbox compatible like Bootstrap4.

.row.flexthis:after, .row.flexthis:before{
  display: none;
}

Answer №3

Although this problem has been around for a while, I came across it today and ended up spending more than 12 hours trying to resolve it. It took me about 10 hours to realize that Safari was struggling with the 12-column Bootstrap grid, and no other issue was causing the problem.

The solution I implemented was quite straightforward. Below is the code for Visual Composer, but keep in mind that class names might be different for other frameworks.

.vc_row-flex:before, .vc_row-flex:after{
  width: 0;
}

Answer №4

To address this issue, I decided against adding additional classes and instead opted to make adjustments directly to the .row class.

.row {
    &:before {
        content: none;
    }

    &:after {
        content: '';
    }
} 

Answer №5

Encountered a problem while attempting to create a basic grid layout using Bootstrap on the TwentyThree CMS, and experienced a similar issue in Safari. However, I was able to resolve it with this solution:

.flex-container:before {
  display: inline;
}

Answer №6

After some troubleshooting, I managed to resolve the issue by inserting

.section:before, .section:after {
align-items: center !important;
}

While not the most sophisticated fix, this workaround could be helpful for others until a more permanent solution is implemented.

Answer №7

There seems to be a bug in Bootstrap 4 that causes issues with the display: block; property on the .row class, whether set through CSS or JavaScript. After some troubleshooting, I found a workaround for this problem.

To fix it, simply create a new class:

.display-block {
display: -webkit-box !important;
display: -ms-flexbox !important;
display: flex !important;
-ms-flex-wrap: wrap !important;
flex-wrap: wrap !important;
}

Then, apply this new class whenever you want to display the row correctly.

Answer №8

I have also dedicated a few hours to resolving this issue. I recently integrated flexbox into an existing project in order to ensure all elements within a row have uniform height. Surprisingly, Safari was the only browser that did not display it correctly, and none of the solutions suggested were effective.

It wasn't until I uncovered a lingering Bootstrap clearfix hack in use: (the code is from a Laravel project, but pertains to generic Bootstrap usage)

@foreach ($articles as $key => $article)
    @if ($key % 3 === 0)
        <div class="clearfix hidden-xs hidden-sm"></div>
    @endif
    @if ($key % 2 === 0)
        <div class="clearfix hidden-lg hidden-md"></div>
    @endif

    etc...
@endforeach

Evidently, browsers other than Safari do not apply the .clearfix property when flexbox is implemented.

Therefore, when using flexbox for columns, Bootstrap's clearfix is no longer necessary.

Answer №9

It appears that there might be a glitch in Safari's rendering that is causing the columns to exceed their boundaries and wrap outside of the Bootstrap container (possibly due to a Webkit rounding error?). If you are utilizing Bootstrap, it should be possible to achieve the desired layout without resorting to flex:

<div class="row">
    <div class="col-md-4 col-sm-6 text-center">
        <div class="product">
            <img src="img.jpg" alt="" class="img-responsive">
            <h3>Name</h3>
            <p>Description</p>
        </div>
    </div>
</div>
<style>
    .product {
        /* Use this code to automatically center and prevent overflow
           on narrow viewports */
        display: inline-block;
        max-width: 100%;
    }
</style>

However, one concern with your current setup is maintaining consistent sizing for your product blocks. You may need to assign a fixed height to .product and make adjustments using media queries to ensure the grid retains its structure.

Here is an example I created that functions smoothly in various browsers, including Safari: http://codepen.io/anon/pen/PZbNMX Furthermore, employing style guidelines can help keep images and text descriptions within specified dimensions for easier maintenance.

Alternatively, exploring scripts or jQuery plugins could offer a more dynamic and uniform sizing solution, although my familiarity with such tools is limited.

I encountered a similar challenge when attempting to blend flex and Bootstrap in Safari, so I trust these suggestions prove beneficial.

Answer №10

Encountering a similar issue, I discovered that Safari has difficulty with floats being cleared within a Flexbox container.

Answer №11

.container:before, .container:after {
content:'';
display:block;
width:100%;
height:0;
}
.container:after {
clear:both;
}

Answer №12

If you're utilizing display flex together with flex-wrap, I found a solution by adding a higher order to the before and after pseudo-elements of the row so that they are positioned as the last elements.

.row.flex_class {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
}
.row.flex_class::before, .row.flex_class::after {
    order: 10;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

CSS PopUp positioning

Can anyone help me with applying the position top and bottom of header to the NewUser div? I've tried but it's not working. How can I add !important; to the CSS? Maybe something like $("header")!important} <div id="divNewUser" class="CreateUs ...

show a pie chart at the top of the div using highcharts

i am struggling with positioning the high-chart with a label, as seen in the image below https://i.sstatic.net/m9bXW.png does anyone know how to properly display the chart from the top left corner? i have attempted to adjust the settings like this { ...

Unable to show the company logo in the navigation bar

Working on a pizza site and encountering an issue - trying to add the logo of the place to the navbar (which also links to the main page) but it's not displaying. Using Twitter Bootstrap for this project. Here is the code snippet: /*#557c3e green*/ ...

Unable to align element to the left due to the position being below

<ul class="unlist clearfix"> <li class="clearfix"> <h3>List Item</h3> <time datetime="2013-08-29"><span>29</span> Ags 2013</time> </li> ...

How can grid be used in CSS/HTML to create two collapsible columns that are side-by-side, maintain equal width, and keep their size when expanded?

Hello all, I'm new here and I have a question that I hope I can explain clearly. I am currently working on creating two collapsible "buttons" positioned side by side (each taking up half of the screen width), which expand when clicked to reveal an equ ...

When a cursor hovers over an image, a dark line appears

I wanted to create a hover effect where the image would enlarge when hovered over. I achieved this using a JavaScript function that applies the transform property with a scale of 1.2 to the picture. However, during the animation, a black line appears at th ...

Is there a way to vertically align the content of two <li> elements when one contains an image within an anchor tag?

I'm attempting to display an HTML unordered list horizontally with each item having the same length and height, while also containing a link. One of the items should also contain an image. My goal is to align these items vertically. To achieve this, ...

Steps for displaying a bootstrap modal in alignment with the triggering button's position

Recently diving into the world of bootstrap and AngularJs has been quite the learning experience for me. One challenge I encountered was trying to implement a bootstrap modal dialog box to show additional details within a table column. My goal was to hav ...

event fails to trigger on a fixed positioned element

Here's the code snippet I've been working with: if ($('body.page-service-map').length || $('body.page-contact').length) { $(document.body).append('<div class="black-overlay"></div>'); ...

The automated test locator in Angular using Protractor is failing to function

I am facing a challenge with my angular web application as there are some elements that are difficult to interact with. One specific element is a checkbox that needs to be checked during testing: ` <div class="row form-group approval_label"> < ...

What steps can be taken to ensure that the header elements such as the image, text, and button are

I am currently working on a website project using Bootstrap 5. For the header section of the site, I have incorporated a carousel from Bootstrap that includes images, text, and buttons. My main objective is to ensure that all elements within the carousel ...

Inject CSS into an iframe containing a JavaScript form by iterating over a collection of iframes

My task is to manipulate an iframe (chatbox) once it's loaded on a webpage. This chatbox consists of four iframes, each with a different id that changes with every page load. Since the iframe that needs manipulation is always the last one in the list, ...

Displaying a variable in a live HTML user interface

I have successfully created a Python program that captures data from an Arduino Potentiometer and shows it on the Python console. Now, I am working on enhancing the output by displaying it in a local HTML file. I am seeking guidance on how to incorporate t ...

"Mastering the art of underlining individual components in React with the power of

Hey there, I'm having some issues working with the CSS for my component. I've created a joke component that has joke and punchline props. The issue is that when it appears in the compiler, my joke component (which I call twice) only shows up as t ...

Simplify your bootstrap Input field code by utilizing components or a similar method in Vue.js

Using a single file component with a pug template, I am faced with multiple input fields that have the same formatting. Here is an example: .input-group.input-group-sm .input-group-addon Purchase Price input.form-control(v-model='purchase_ ...

Divide the width by half in a CSS grid layout with 3 columns

Is it possible to replicate the layout shown in the image using CSS grid? https://i.sstatic.net/XSoE8.png ...

Two-toned diagonal design featuring a lone character

I'm searching for a unique design featuring the letter "d" in two colors, arranged diagonally without any gradient effects. Here is the CSS code I am currently using: .gradient_text_class { font-size: 72px; background-image: linear-gradient(50de ...

Utilize the ::before selector to insert white spaces

I attempted this solution, but unfortunately it did not produce the desired outcome: .stackoverflow::before { font-family: 'FontAwesome'; content: "\f16c "; } <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-aw ...

Issue with fluid layout in CSS - Unable to specify height in pixels and minimum height property not functioning as expected

While working on a liquid layout, I have set all my width and height values in percentages. However, during the design process, I needed to check how my CSS was rendering so I temporarily set the height in pixels. Eventually, the height in percentage wil ...

Creating sequential hover animations with CSS in HTML

I have a total of four divs that I want to hover continuously, one after the other. Here is the code I am currently using: #rij1 .content-overlayz, #rij1 .content-details { animation-duration: 2s; animation-name: stepped-pulse; animation-iterati ...