5

Where Chrome contains the SVG, Safari lets it stretch to a much larger size. Not sure what I can do to get rid of that behavior.

Here's a pen: https://codepen.io/sashakevich/pen/boEPdb In Chrome it's perfect, in Safari the images are too large.

And here's the code:

* {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

.row {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
  padding: 30px 10px;
}

.text-item {
  -ms-flex-preferred-size: 200px;
  flex-basis: 200px;
  margin: 0 1.5%;
}

.img-item {
  -ms-flex-preferred-size: 33%;
  flex-basis: 33%;
  margin: 0 1.5%;
  -webkit-box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.4);
  box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.4);
  background: #fff;
  border-radius: 3px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  padding: 25px 35px;
  min-height: 200px;
}

.img-item img {
  width: 100%;
  height: auto;
}
<div class="row" style="background:#f1f1f1;">
  <div class="text-item">
    <p>A remake of their old logo of a kid holding a toothbrush.</p>
  </div>
  <div class="img-item">
    <img src="https://www.simplylogos.net/wp-content/uploads/svg_port/sl-franklin-1.svg">
  </div>
  <div class="img-item">
    <img src="https://www.simplylogos.net/wp-content/uploads/svg_port/sl-franklin-2.svg">
  </div>
  <div class="img-item">
    <img src="https://www.simplylogos.net/wp-content/uploads/svg_port/sl-franklin-3.svg">
  </div>
</div>
<div class="row" style="background:#e1e1e1;">
  <div class="text-item">
    <p>A remake of their old logo of a kid holding a toothbrush.</p>
  </div>
  <div class="img-item">
    <img src="https://www.simplylogos.net/wp-content/uploads/svg_port/sl-mogtel-3.svg">
  </div>
  <div class="img-item">
    <img src="https://www.simplylogos.net/wp-content/uploads/svg_port/sl-mogtel-1.svg">
  </div>
  <div class="img-item">
    <img src="https://www.simplylogos.net/wp-content/uploads/svg_port/sl-mogtel-2.svg">
  </div>
</div>

@Steve-Schrab's flex shrink solution didn't help - SVG in flexbox messes up height of other elements) (Maybe I'm running into the Implied Minimum Size of Flex Items as suggested by @michael_b here: Why doesn't flex item shrink past content size? but if I am, I don't know what to do to make it behave.

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
sashaikevich
  • 167
  • 13
  • Remove `display: flex` from the `img-item` – Asons Sep 19 '17 at 17:33
  • @LGSon that doesn't really help. I have flex on the parent, because it centers the children both vertically and horizontally without me having to mess about with transforms. I'm not entirely against going that route, but want to see if a more elegant solution is available. Besides, it only retains the size when i get rid of both: display: -ms-flexbox; display: flex; I have to keep: display: -webkit-box; ...but it's inconsistent: https://developer.mozilla.org/en-US/docs/Web/CSS/box-flex. If I get rid of it too, then the images do exactly what I try to avoid. – sashaikevich Sep 19 '17 at 20:50

1 Answers1

0

It seems min-height on the .img-item is causing the issue. Changing this to max-height might get the desired result.

* {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

.row {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
  padding: 30px 10px;
}

.text-item {
  -ms-flex-preferred-size: 200px;
  flex-basis: 200px;
  margin: 0 1.5%;
}

.img-item {
  -ms-flex-preferred-size: 33%;
  flex-basis: 33%;
  margin: 0 1.5%;
  -webkit-box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.4);
  box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.4);
  background: #fff;
  border-radius: 3px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  /*  justify-content: center; */
  /*  align-self: stretch; */
  padding: 25px 35px;
  min-height: 200px;
  /* position: relative; */
}

.img-item img {
  width: 100%;
  height: auto;
}
<div class="row" style="background:#f1f1f1;">
  <div class="text-item">
    <p>A remake of their old logo of a kid holding a toothbrush.</p>
  </div>
  <div class="img-item"><img src="https://www.simplylogos.net/wp-content/uploads/svg_port/sl-franklin-1.svg"></div>
  <div class="img-item"><img src="https://www.simplylogos.net/wp-content/uploads/svg_port/sl-franklin-2.svg"></div>
  <div class="img-item"><img src="https://www.simplylogos.net/wp-content/uploads/svg_port/sl-franklin-3.svg"></div>
</div>
<div class="row" style="background:#e1e1e1;">
  <div class="text-item">
    <p>A remake of their old logo of a kid holding a toothbrush.</p>
  </div>
  <div class="img-item"><img src="https://www.simplylogos.net/wp-content/uploads/svg_port/sl-mogtel-3.svg"></div>
  <div class="img-item"><img src="https://www.simplylogos.net/wp-content/uploads/svg_port/sl-mogtel-1.svg"></div>
  <div class="img-item"><img src="https://www.simplylogos.net/wp-content/uploads/svg_port/sl-mogtel-2.svg"></div>
</div>
Brett DeWoody
  • 59,771
  • 29
  • 135
  • 184
  • 1
    Yeah, kinda. I mean it restricts it well enough in Safari, but in the full code I use media queries, so when it's a smartphone for example, the flex-basis is 100% and the height is greater than the desktop version. Worst case, I will write those extra rules, but I was hoping to 1) Learn why Safari is behaving differently, and 2) Find a solution that doesn't require quite so much code (I have a few tablet conditions too). – sashaikevich Sep 19 '17 at 21:01