简体   繁体   English

使用SVG作为背景图片<li>

[英]Using SVG as background image for <li>

I'm trying to use an SVG as a background image for the elements in a list but it is not working. 我正在尝试使用SVG作为列表中元素的背景图像,但是它不起作用。 I'm not sure if it's me or if it is the SVG itself. 我不确定是我还是SVG本身。

Here is the code for my nav 这是我的导航的代码

     <nav>
        <ul>
         <li class="completed"><a href="#">Exam</a> <i class="fa fa-check-circle"></i></li>
         <li><a href="#">Personal <i class="fa fa-times-circle"></i></a></li>
         <li><a href="#">Employment</a></li>
         <li><a href="#">Appointment</a></li>
         <li><a href="#">Record Check</a></li>
         <li><a href="#">Submit</a></li>
        </ul>
     </nav> 

Here is the code where I try to apply the SVG 这是我尝试应用SVG的代码

nav > ul > li > a {
    display: inline;
    /*background-color: white;*/
    color: rgba(119, 119, 119, 0.59);
    background: url(../images/navPill.svg);
    background-size: cover;
}

And here is a link to the SVG 这是SVG的链接

http://expirebox.com/download/13169ec086d8af7dd7ad4e5fe3f2d1ad.html [broken now] http://expirebox.com/download/13169ec086d8af7dd7ad4e5fe3f2d1ad.html [立即中断]

You probably want to use background-size: contain instead of cover to make the arrow fit inside each of the links. 您可能要使用background-size: contain而不是cover以使箭头适合每个链接。 However, when you use contain and the svg is shrunk, the thin arrow line is too faint to see. 但是,当您使用contain与SVG收缩,细箭头线太微弱看到的。

Here is a working example. 这是一个工作示例。 I have only changed cover to contain and added a black fill to the arrow so you can see it: 我只是将cover更改为contain并在箭头上添加了黑色填充,因此您可以看到它:

http://jsfiddle.net/68j04n3j/ http://jsfiddle.net/68j04n3j/

Here's a better version of the SVG for this situation: 这是针对这种情况的SVG的更好版本:

<svg
    xmlns="http://www.w3.org/2000/svg"
    xmlns:xl="http://www.w3.org/1999/xlink" version="1.1"
    width="576" height="152" viewbox="0 0 576 152">
  <path transform="translate(10,-185)" d="M 0 189.5 L 39.741071 261.25 L 0 333.125 L 516.63393 332 L 556.375 260 L 516.63393 188 L 0 189.5 Z" stroke="black" stroke-linecap="butt" stroke-linejoin="miter" stroke-width="10" fill="transparent" />
</svg>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM