【发布时间】:2022-01-03 17:38:49
【问题描述】:
今天想使用 background-size 属性在 svg 上设置背景的大小,但没有成功,因为背景不是图像,而是普通颜色 (#ecf2f8)
这是我的代码:
#svg-social {
position: absolute;
right: 50px;
bottom: 45px;
background-color: #ecf2f8;
border-radius: 100px;
}
<p id="main-text">
Ever been in a room and felt like something was missing?<br> Perhaps
it felt slightly bare and uninviting. I’ve got some<br> simple tips
to help you make any room feel complete.</p>
<div id="author">
<img src="/images/avatar-michelle.jpg" alt="Michelle Appleton avatar" id="avatar">
<h5 id="name">Michelle Appleton</h5>
<p id="date">28 Jun 2020</p>
</div>
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="13" id="svg-social">
<path fill="#6E8098"
d="M15 6.495L8.766.014V3.88H7.441C3.33 3.88 0 7.039 0 10.936v2.049l.589-.612C2.59 10.294 5.422 9.11 8.39 9.11h.375v3.867L15 6.495z" />
</svg>
<div id="socials">
<div id="triangle"></div>
</div>
</div>
祝你有美好的一天!
【问题讨论】:
-
您能否发布所有代码,包括生成 SVG 的 html 以使您的代码可重现(我们可以运行它并自行检查)?
-
@RyanMillares 完成
-
我会为 svg 元素使用 viewBox,例如
viewBox="-5 -5 25 25"。如果您选择 viewBox 解决方案,请删除 svg 元素的高度。您也可以选择不同的宽度。请阅读更多关于viewBox attribute