Exploring the wild: adjusting heights of flex items in Safari

I am facing an issue with my flex container and images. When using flexwrap and setting the flex-item width to 33%, the images look perfect in Chrome as they maintain their aspect ratios. However, in Safari, the images get stretched vertically, which is not visually appealing at all.

Is there a solution to this problem?

(Please open this post in both Chrome and Safari to see the difference described below)

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>

    <body>
        <div class="container">
            <img src='https://swipestack.s3.amazonaws.com/s/q/1.jpg' alt='1'>
            <img src='https://swipestack.s3.amazonaws.com/s/q/2.jpg' alt='2'>
            <img src='https://swipestack.s3.amazonaws.com/s/q/3.jpg' alt='3'>
            <img src='https://swipestack.s3.amazonaws.com/s/q/4.jpg' alt='4'>
            <img src='https://swipestack.s3.amazonaws.com/s/q/5.jpg' alt='5'>
            <img src='https://swipestack.s3.amazonaws.com/s/q/6.jpg' alt='6'>
            <img src='https://swipestack.s3.amazonaws.com/s/q/7.jpg' alt='7'>
            <img src='https://swipestack.s3.amazonaws.com/s/q/8.jpg' alt='8'>
        </div>
        
    </body>
    
    <style>
        .container{
            display: flex;
            flex-wrap: wrap;
            overflow: auto;
            width: 400px;
            height: 550px;
            padding: 10px;
            background-color: green;
        }
        .container > * {
            width: 33.33333%;
        }

    </style>
</html>

Answer №1

Here is a solution that will work if you ensure the first and second images have a height of 475px, just like the others:

   <style>
    .container {
      width: 400px;
      height: 550px;
      padding: 10px;
      background-color: green;
      overflow: auto;
    }

    .container:first-child {
      display: flex;
      flex-wrap: wrap;
      align-items: flex-start;
    }
    .container > * {
      width: 33.33333%;
      height: auto;
    }
  </style>

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

Tips for condensing text using ellipsis and Angular-FlexLayout

I am working on a flex row setup that includes three nested flex rows. Within the second row, I need to display a title that should not be shortened, and a text that should be truncated. Additionally, the first and last row must maintain a fixed width with ...

What is the best way to automatically assign a class attribute to all form widgets in Django?

Whenever I create a form using Django, I want the input tag to automatically include a specific CSS class (form-control). Currently, I have to manually add lines of code in my forms.py file for each field like this: class InsertItem(forms.ModelForm): ...

Issues with adjusting the height using CSS transformations are not being resolved

There seems to be an issue with animating the height property of an element as it is not animating at all. Check out the fiddle where the animation is attempted. Here is the HTML: <ul> <li> li 1 </li> <li> ...

"Ensuring Your SVG Icon is Perfectly Centered: A Step

My SVG icon is currently aligned to the left, but I want to center it. I tried using the following code, but it doesn't seem to be working: .parent{ display: flex; align-items: center; font-size: 13px; } span{ margin-right:10px } https://i.sstatic.ne ...

Utilizing React's Conditional Rendering Alongside Bootstrap to Maintain the Layout Intact

I'm currently developing a project using React and Bootstrap that involves incorporating a large bar graph with two smaller boxes, all positioned horizontally together. To visualize how it should appear, please expand the pen window to see them arran ...

Tips for preserving scroll location on Angular components (not the window) when navigating

My current layout setup is like this: https://i.sstatic.net/hOTbe.png In essence <navbar/> <router-outlet/> The issue I'm facing is that the router-outlet has overflow: scroll, making it scrollable (just the outlet section, not the ent ...

Ensure the full-width background includes a top margin to prevent the image's top from being cut off (wp-supersized)

I have implemented wp-supersized to create a full-width background that dynamically resizes. You can find more about it here. Check out what I have done so far at this link. My challenge is with a fixed height header set at 154px. I want the top of the i ...

Aligning text and lists using Bootstrap on both desktop and mobile devices

I want to format a text with a list similar to the images provided https://i.stack.imgur.com/6giDH.png for desktop and tablet view, but for mobile display I would like it to look like this https://i.stack.imgur.com/7zSXi.png This is my current approach ...

Splitting areas within a liquid vessel using bootstrap 5

My container is structured like this with divisions: <div class="container-fluid"> <div class="row"> <div class="col-3"> sidebar </div> <div class="col-7"> top slider </div> <di ...

What is hindering the responsiveness of this HTML table?

I recently designed a schedule table that resizes properly in the browser, but when I tried to access it on my mobile phone, it didn't resize correctly. On my phone screen, half of Thursday was cut off due to the horizontal scroll. https://i.sstatic. ...

Tips for managing a date picker with JavaScript using the Selenium WebDriver

I have been attempting to scrape a travel website using Selenium Webdriver and Python. While I have successfully set the destination (destino) and place of origin (origem), I am encountering difficulties when trying to select a date. I understand that Ja ...

Reduce the transparency of the overlay picture

I have been utilizing the 'Big Picture' template to design a webpage. The overlay.png file adds a lighter background effect by overlaying intro.jpg with a partially transparent blue graphic. Despite my efforts to adjust the opacity and gradient/R ...

Shifting the size of a React element with animation

Within my React-based application, I am attempting to execute a basic CSS3 width transition with the following code: .foo { transition: width 1s ease-in-out; } My objective is to apply a style to an element in the React component which is "width: xx% ...

What is the best way to apply different styles to alternative children within a dynamically generated list?

I am currently implementing the following code snippet: $('.js-toprow:nth-child(even)').css("background:", "#ddd"); $('.js-toprow:nth-child(odd)').css("background:", "#ff0000"); Within the function: function resetSlides() { conta ...

`We are experiencing alignment issues with the Bootstrap drop-down menu`

I'm struggling to understand why my menu isn't aligning properly on the sub dropdowns. They are appearing at the lower edge of their parent cell, making navigation quite difficult. You have to drop down diagonally just right to access the next me ...

What could be the reason behind a CSS caption overlapping another image within this table?

This is the CSS caption effect I am using: .cell { position: relative; width: 180px; height: 180px; } .caption {} .cell .caption { opacity: 0; text-decoration-color: gray; text-align: center; background: #eaeaea; position: absolute; fo ...

Having trouble identifying the elements within a Div pop-up in Chrome when executing Selenium automation

When automating on the website automationpractice.com, follow these steps: 1. Open "automationpractice.com/index.php?id_product=5&controller=product#/size-s/color-orange" 2. Click on the "Add to Cart" button 3. The successful "Add to Cart" pop-up will ...

Resizing images within a container using Bootstrap to fit the screen dimensions

I am having an issue with my bootstrap page where the tiles adjust position based on screen size. Everything works well except when I try to add images to the tiles along with other content. In the example below, you can see that the first tile has an imag ...

Is there a way to have a border specifically on the top side?

Is there a way to have the border show up only on the top when hovering over it? Here's the current code I'm using: a:hover { border-top: 3px white; border-style: solid; } Even though this code is in place, the border still appears on ...

Can the ID attribute be used in the closing tag of an HTML element

Could this code be improved by properly closing the div with an ID: <html> <body> <div id="main"> </div id=main"> </body> </html> ...