【问题标题】:How to add a border to a background-image that contains a svg?如何为包含 svg 的背景图像添加边框?
【发布时间】:2017-11-18 21:24:13
【问题描述】:

就像标题一样,我无法在包含 svg 的背景图像周围设置边框。 当我尝试在该背景图像上使用 css 边框时,边框将向内并减小图像。 我读过一些关于使用 svg:image 的内容,但对我来说,我必须编辑 svg 代码本身才能获得边框。 没有办法用 CSS 解决吗?

已解决

感谢您的回答。但正如我所说,我不想更改 svg 文件中的任何内容。 我为自己找到了一个可行的解决方案。

.s-icon {
  height: 50px;
  text-align: center;
  width: 50px;
}

.s-icon--border {
  background-color: lightblue;
  -webkit-border-radius: 50px;
  -moz-border-radius: 50px;
  border-radius: 50px;
  line-height: 0;
  border: 4px solid lightskyblue;
}

https://codepen.io/anon/pen/eRBQoE

【问题讨论】:

  • 你能在 jsfiddle 或 plunker 上提供你的代码吗?

标签: css svg background-image border


【解决方案1】:

在填充=“无”的图像周围画一个<rect>。可以使用<rect>的笔画作为边框。

【讨论】:

    【解决方案2】:

    你可以用 box-shadow 做到这一点

    div {
      width: 200px;
      height: 100px;
      background: tomato;
      box-shadow: 0 0 0 5px rgba(0,0,0,1);
    }
    <div></div>

    【讨论】:

      猜你喜欢
      • 2013-01-22
      • 2017-01-14
      • 2018-06-26
      • 2019-06-24
      • 1970-01-01
      • 2021-02-09
      • 2018-12-22
      • 1970-01-01
      相关资源
      最近更新 更多