gpt4 book ai didi

css - Flex div 中的 SVG 图像在 Safari 和 Chrome 中的显示方式不同

转载 作者:行者123 更新时间:2023-12-03 21:28:28 24 4
gpt4 key购买 nike

在 Chrome 包含 SVG 的地方,Safari 让它扩展到更大的尺寸。不知道我能做些什么来摆脱这种行为。

这是一支笔:https://codepen.io/sashakevich/pen/boEPdb
在 Chrome 中它是完美的,在 Safari 中图像太大。

这是代码:

* {
-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 的 flex 收缩解决方案没有帮助 - SVG in flexbox messes up height of other elements )
(也许我遇到了@michael_b 在这里建议的 Flex 元素的隐含最小尺寸: Why doesn't flex item shrink past content size? 但如果我遇到了,我不知道该怎么做才能让它表现出来。

最佳答案

好像min-height.img-item导致问题。将此更改为 max-height可能会得到想要的结果。

* {
-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>

关于css - Flex div 中的 SVG 图像在 Safari 和 Chrome 中的显示方式不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46306537/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com