gpt4 book ai didi

css - SVG 背景图像缩放问题

转载 作者:行者123 更新时间:2023-11-28 15:00:43 25 4
gpt4 key购买 nike

我在 before 伪元素上使用 SVG(白色三 Angular 形)作为背景图像,如图所示。如果我将高度设置为与 SVG 大小相同,则它没有半像素线。但是因为我需要它来响应,所以我将背景大小设置为“覆盖”(如果我使用“包含”,结果相同)。

这是我用白色三 Angular 形实现红色条纹的 CSS 代码:

#careers{margin:7em 0 0}
#careers a{width:100%;height:auto;overflow:hidden;display:block;-webkit-box-shadow:7px 10px 11px 0 rgba(0,0,0,.16);-moz-box-shadow:7px 10px 11px 0 rgba(0,0,0,.16);box-shadow:7px 10px 11px 0 rgba(0,0,0,.16)}
#careers a img{width:100%;height:auto;-webkit-transition:all .2s linear;-moz-transition:all .2s linear;-ms-transition:all .2s linear;-o-transition:all .2s linear;transition:all .2s linear;display:block;z-index:10}
#careers a:hover img{-webkit-transform:scale(1.05);-moz-transform:scale(1.05);-o-transform:scale(1.05);transform:scale(1.05)}
#careers .col-md-5{z-index:15}
#careers .careers-holder{padding:0 15% 0 15px;color:#fff;z-index:10}
#careers .careers-holder .btn{width:auto;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;display:inline-block}
#careers::before{content:'';position:absolute;width:calc(100% - 4.1666665%);height:385px;left:0;right:0;top:50%;-webkit-transform:translateY(-50%);-moz-transform:translateY(-50%);-o-transform:translateY(-50%);transform:translateY(-50%);background:#d02139 url(http://ranfurlie.website.2018.360southclients.net:8080/img/icon-triangle-white.svg) top right no-repeat;background-size:cover;z-index:1}
<section id="careers">
<div class="container-fluid">
<div class="row vertical-align">
<div class="col-md-1"></div>
<div class="col-md-5">
<a href="<?php echo $careers_link; ?>"><img src="<?php echo $careers_image[0]; ?>" width="705" height="450" alt="Careers" /></a>
</div>
<div class="col-md-5 careers-holder">
<h3>Careers</h3>
<h2>Interested in working for us?</h2>
<p>We are rapidly growing and always need talent to continue our pace. If you’re up for a great challenges and the rewarding career, check out our current positions available.</p>
<a href="<?php echo $careers_link; ?>" class="btn white">Read more</a>
</div>
<div class="col-md-1"></div>
</div>
</div>
</section>

这是该部分的 HTML:

1 pixel line

知道为什么会有半个红色像素吗? SVG 背景图像设置为右上角。

SVG 本身可以在这里找到:

http://ranfurlie.website.2018.360southclients.net:8080/img/icon-triangle-white.svg

编辑:我在 SVG 代码中添加了设置宽度和高度,这似乎已经解决了 Firefox 的像素问题,但它仍然显示在 Chrome 上。我没有 mac 来测试其他浏览器。

最佳答案

不要在 SVG 元素中添加 widthheight,或者在 CSS 中添加 background-size:cover。 SVG 定位和调整大小的方式通过属性 preserveAspectRatio 起作用:

<svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 347 385" preserveAspectRatio="xMaxYMax slice">

它将确保 viewBox 覆盖整个元素背景,并定位为使右上角重合。

(不评估在 svg 元素上设置的其余属性。)

关于css - SVG 背景图像缩放问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50209072/

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