Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

css - Safari stretching flex item heights

I have a flex container, and in that container, I have a bunch of images. Using flexwrap, and a flex-item width of 33%, this presents the images nicely ... in Chrome (that is, they maintain their aspect ratios). In Safari, however, the images get stretched in the vertical direction which looks terrible.

Is there a fix for this?

(Note: For the code snippet below, you will have to open this post in both Chrome and Safari to see what I am talking about)

<!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>
question from:https://stackoverflow.com/questions/66064872/safari-stretching-flex-item-heights

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you can try this, which works only if you give the first and second images the same height of 475px as 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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...