Is there a solution to resolve the flex 50% layout problem specifically in Safari?

Currently, I am facing an issue with Safari (Version 10.1.2 (12603.3.8)) while working on a small example of flex layout.

The problem arises when I attempt to place four boxes inside a content div in a 2x2 layout and have them fill the height and width by 50%. However, in Safari, the footer section seems to be disregarded, causing the boxes to align to the full page instead.

I aim to achieve this layout (which works perfectly in Chrome): https://i.sstatic.net/jLONP.png

But unfortunately, here is how it appears in Safari: https://i.sstatic.net/oZgYT.png

In my testing, I found that the layout functions as expected in High Sierra with a newer version of Safari (Ver. 11). This suggests a bug in Safari 10. Is there a workaround for this issue in Safari 10? Thank you!

Below is the code I have been working with:

HTML:

* {
      box-sizing: border-box;
    }

    body, html {
      width: 100%;
      height: 100%;
      margin: 0;
    }

    .wrapper {
      display: flex;
      flex-direction: column;
      height: 100%;
    }

    .content {
      display: flex;
      flex-wrap: wrap;
      width: 100%;
      height: 100%;
      background: white;
      border: 1px solid tomato;
    }

    .box {
      width: 50%;
      height: 50%;
      background: skyblue;
      border: 1px solid black;
    }

    .footer {
      opacity: 0.7;
      flex: 0 0 auto;
      height: 100px;
      background: plum;
    }
<div class="wrapper">
      <div class="content">
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>    
      </div>
      <div class="footer"></div>
    </div>

Answer №1

When dealing with a flex column item like content, it is recommended to use flex-grow rather than specifying a height.

To ensure content fills its parent, remove the height property and include flex-grow: 1:

.content {
  flex-grow: 1;                    /*  added  */
  display: flex;
  flex-wrap: wrap;
  background: white;
  border: 1px solid tomato;
}

Additionally, there is no need to set width: 100% as it is the default behavior.

Check out the Stack snippet below:

* {
  box-sizing: border-box;
}

body, html {
  width: 100%;
  height: 100%;
  margin: 0;
}

.wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.content {
  flex-grow: 1;
  display: flex;
  flex-wrap: wrap;
  background: white;
  border: 1px solid tomato;
}

.box {
  width: 50%;
  background: skyblue;
  border: 1px solid black;
}

.footer {
  opacity: 0.7;
  flex: 0 0 auto;
  height: 100px;
  background: plum;
}
<div class="wrapper">

  <div class="content">
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>    
  </div>

  <div class="footer"></div>

</div>

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

Submitting a form using jquery in HTML

Below is the code I have created. It consists of a text-input field and a 'Search' button within a form. Upon clicking the search button (submitting the form), it should trigger the .submit function to carry out the necessary processing. HTML CO ...

How can I position a Bootstrap dropdown textbox or menu directly beneath its button?

Currently, I am working on implementing a simple dropdown textbox for a button within a navbar. However, I am encountering an issue where the text does not drop below the button as expected. Initially, it was displaying to the left, obstructing the brand l ...

lines stay unbroken in angular

I am encountering an issue when I execute the following code: DetailDisplayer(row) : String { let resultAsString = ""; console.log(row.metadata.questions.length); (row.metadata.questions.length != 0 )?resultAsString += "Questions ...

Apply a gradient background color to the entire side menu

I recently completed a project using Ionic 3 with a side menu. I am now trying to implement a gradient background color for the entire side menu, but it's proving to be more challenging than expected. Any suggestions or ideas on how to achieve this? ...

A paragraph styled with line numbers using CSS

I struggle with writing long, never-ending paragraphs and need a way to visually break them up by adding line numbers next to each paragraph. While I'd prefer a solution using only CSS for simplicity's sake, JavaScript works too since this is jus ...

Transferring Arrays from PHP Script to JavaScript Script

Can someone help me figure out how to pass an array from my PHP file to a JavaScript file? Here is the array I have: $pictures = array( "1" => array("caption" => "1920x1200px", "tag" => "wallpaper", "link" => "#"), ); In my JavaScript file, I ...

Obtain the row ID from a database by selecting checkboxes

I am facing a challenge when trying to remove a row from my MS Access database using checkboxes on my JSP page. Each row in the displayed database has a checkbox, but I am struggling to retrieve the rowId and link each checkbox with its respective row. Any ...

Incorporating shadow effects along the right border of alternating table cells: a step-by-step guide

How can I set a proper shadow border for alternating td elements in a table? I've been experimenting with the code below. While the shadow effects work, they are getting cut off at each td junction. Can anyone provide assistance? Here is my table: ...

Is the User Agent Stylesheet giving h1 elements a default bold setting?

My h1 is appearing bold due to the user agent stylesheet, but I want it to be normal. How can I override this? h1 { display: block; font-size: 2em; -webkit-margin-before: 0.67em; -webkit-margin-after: 0.67em; -webkit-margin-start: 0px; -webkit-margin-end: ...

Problem with dropdown menu on Internet Explorer 9

Encountering a problem with a dynamic dropdown list in Internet Explorer 9. A table populates one of its columns with individual combo boxes, each created using HTML 5.0 code like this: <select id="cboABC0" class="RetrieveList cboABC" data-index="0" d ...

Unable to get CSS hover effect to overlay

Can anyone help me figure out why the .cd-img-overlay class is not functioning properly when I hover over a list item? Check out my live code here CSS: #cd-team .cd-img-overlay { position: absolute; top: 0; left: 0; width: 100%; h ...

Show off a font-awesome icon overlapping another image

My task involves fetching image source from a JSON file and then displaying it on an HTML page. https://i.sstatic.net/coOaU.png I also need to overlay a Font Awesome icon on top of the image as shown below: https://i.sstatic.net/nbrLk.png https://i.sst ...

Submitting information from a lone row within a table that is contained within a single form

Within my form, there is a table containing records generated by a for loop iterating through items in a list. Each record has a submit button that triggers an AJAX call to serialize and POST the form data to the controller. The goal is to only POST data f ...

What could be causing certain JS files to fail to load in HTML?

I'm facing an issue with loading multiple JavaScript files in my HTML code. Only the jQuery file is loading, while the other two files are not. Could someone please help me identify the mistake I am making? When I check the network tab using the inspe ...

Tips for utilizing sorting, searching, and pagination features in Bootstrap 5 tables

In my simple table, https://i.sstatic.net/bu1md.png Furthermore, I have integrated Bootstrap 5: <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="15777a ...

Are font classifications determined by the operating system of the viewer or the web browser of the viewer

One thing I've observed is that Google Fonts never uses "fantasy" as a fallback class in the font-family. Instead, they utilize "cursive" for all script and typical fantasy fonts. Could this be a subtle indication that Chrome does not support "fantas ...

Create a container div with a set width and height, and use

When wrapping a div, I typically rely on the overflow:hidden method. However, I am wondering if there are alternative methods to wrap divs that do not involve using hidden overflow. This is because I have some specific concerns that prevent me from utili ...

Characteristics Exclusive to Inner Division

Currently, I am working on creating an arrow-like element that moves up when hovered over and returns to its original position when the mouse is no longer hovering. To achieve this effect, I have placed the arrow within a parent div and set up event listen ...

"Taking cues from Instagram's web/desktop design, we have created

When you view someone's instagram page on a desktop or pc, the search bar is designed to float left when clicked, allowing text to be entered for searching. If no text is entered in the search field, the search icon and placeholder return to their ori ...

Swapping out a style sheet within a intricate header

I'm in search of help with creating a stylesheet switcher for my website. My knowledge of html/css/js is self-taught, so I ask for forgiveness for any beginner mistakes. I have customized some code to fit my requirements, but I am unsure how to target ...