Svg 在 Safari 中<img>缩放错误

问题描述 投票:0回答:1

我目前正在制作一个简单的网站,我想嵌入从一些 api here 获得的不和谐的丰富存在 svg。我使用

<img>
标签将其嵌入到页面中。现在,我正在尝试实现媒体查询,以使网站能够在不同的设备上正确扩展。我编写了一个简单的 CSS,可以在 Chrome、Firefox 和 Opera 上运行,并正确缩小 img 元素 (svg)。它也适用于我的装有 Chrome 的 Android 手机。但是,img 在 Safari 上无法正确缩放(Mac 和 iPhone 版本均如此)。 svg 被裁剪,并且它不想适合正确缩放的
<img>
容器。

预期结果:

目前结果:

我尝试添加不同的 css webkit 规则并摆弄不同的大小。当宽度设置为 400px 这样的常数时,不会出现此问题,但我希望大小具有响应能力。

@import url(https://fonts.googleapis.com/css2?family=Share+Tech+Mono&display=swap);
a,
h2 {
  background-image: -webkit-gradient(
    linear,
    left top,
    right top,
    from(#11998e),
    to(#28a859)
  );
  background-image: -o-linear-gradient(left, #11998e, #28a859);
  color: transparent;
}
.hero-text,
footer {
  text-align: center;
}
* {
  margin: 0;
  padding: 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  font-family: "Share Tech Mono", monospace;
  font-weight: 400;
}
html {
  font-size: 18px;
}
body {
  min-height: 100vh;
  background-color: #191919;
  color: #bbb;
}

.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  background-color: #313131;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  box-shadow: 0 5px 5px rgba(0, 0, 0, 0.2);
  padding: 0.5rem 2rem;
}

.hero {
  height: 30rem;
  margin: 0 4rem;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
}
.section-intro,
main {
  display: -webkit-box;
  display: -ms-flexbox;
}
h1 {
  font-size: 5.61rem;
}
h2 {
  font-size: 3.157rem;
  background-image: linear-gradient(to right, #11998e, #28a859);
  -webkit-background-clip: text;
  background-clip: text;
}
h3 {
  font-size: 2.369rem;
}
main {
  margin-bottom: 7rem;
  width: 100vw;
  padding: 0 10vw;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
}
section {
  margin-bottom: 4rem;
  max-width: 30rem;
}
.section-intro {
  display: flex;
  -ms-flex-align: center;
  -webkit-box-align: center;
  align-items: center;
  margin-bottom: 0.5rem;
}
section > ul > li {
  text-align: left;
  font-size: 1rem;
  margin-left: 1rem;
}
section > p {
  font-size: 1rem;
  text-align: justify;
}
.section-intro > img {
  width: 3.6rem;
  height: 100%;
  margin-right: 1rem;
}

a {
  font-size: inherit;
  background-image: linear-gradient(to right, #11998e, #28a859);
  -webkit-background-clip: text;
  background-clip: text;
}

a:hover {
  background-image: linear-gradient(to right, #0c746b, #1a6e3a);
}

.discord-presence {
  margin: 0 auto;
  max-width: 40vw;
  min-width: 20vw;
}

footer {
  padding: 1.6rem;
}

@media screen and (max-width: 992px) {
  h1 {
    font-size: 4.209rem;
  }
  section {
    margin-bottom: 4rem;
    max-width: 25rem;
    text-align: justify;
  }
  .discord-presence {
    margin: 0 auto;
    max-width: 55vw;
    min-width: 40vw;
  }
}

@media screen and (max-width: 680px) {
  h2 {
    font-size: 1.953rem;
  }
  h3 {
    font-size: 2.369rem;
  }
}

@media screen and (max-width: 480px) {
  h1 {
    font-size: 3.052rem;
  }
  h2 {
    font-size: 1.953rem;
  }
}


.noselect {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
<main>
 <div>
 <!-- More content goes here.... -->
 </div>
  <img class="discord-presence noselect" src="https://lanyard.cnrad.dev/api/175652881456693249" alt="" />
</main>
<footer>xxxxx</footer>

html css safari
1个回答
0
投票

body {
  background-color: #191919;
}

.discord-presence {
  border: 1px solid yellow;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

footer {
  padding: 1.6rem;
}
<main>
  <img class="discord-presence" src="https://lanyard.cnrad.dev/api/175652881456693249">
  <img class="discord-presence" src="https://donald.au/bugs/so-78306128.svg">
</main>

© www.soinside.com 2019 - 2024. All rights reserved.