将CSS嵌入SVG以创建脉动圆

时间:2018-12-16 23:39:18

标签: html css svg

是否可以将Codepen CSS嵌入SVG中以创建独立的SVG文件(即图标)?基本上将整个Codepen代码转换为1个.svg文件

This is the link to the Codepen

def _check_is_chained_assignment_possible(self):
    """
    Check if we are a view, have a cacher, and are of mixed type.
    If so, then force a setitem_copy check.
    Should be called just near setting a value
    Will return a boolean if it we are a view and are cached, but a
    single-dtype meaning that the cacher should be updated following
    setting.
    """
    if self._is_view and self._is_cached:
        ref = self._get_cacher()
        if ref is not None and ref._is_mixed_type:
            self._check_setitem_copy(stacklevel=4, t='referant',
                                     force=True)
        return True
    elif self._is_copy:
        self._check_setitem_copy(stacklevel=4, t='referant')
    return False

1 个答案:

答案 0 :(得分:2)

根据doc,您可以在<style>中使用<svg>元素。

另一方面,请注意,您的Codepen位于 SCSS 中,而不位于 CSS 中。

这里是一个示例,其中我将您的代码快速转换为CSS:

<div class="pulse-container">
  <div class="pulse-box">
    <svg class="pulse-svg" width="50px" height="50px" viewBox="0 0 50 50" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    
    <style>
    /* <![CDATA[ */

.pulse-box {
  float: left;
  width: 50%;
  height: 250px;
  display: flex;
  justify-content: center;
  align-items: center;
}
/* pulse in SVG */
svg.pulse-svg {
  overflow: visible;
}

  svg.pulse-svg .first-circle {
    fill: #f00;
    transform: scale(0.5);
    transform-origin: center center;
    animation: pulse-me 3s linear infinite;
  }
 svg.pulse-svg .second-circle {
     fill: #f00;
    transform: scale(0.5);
    transform-origin: center center;
    animation: pulse-me 3s linear infinite;
    animation-delay: 1s;
  }
 svg.pulse-svg .third-circle {
       fill: #f00;
    transform: scale(0.5);
    transform-origin: center center;
    animation: pulse-me 3s linear infinite;
    animation-delay: 2s;
  }


/* pulse in CSS */
.pulse-css {
width: 30px;
  height:  30px;
  border-radius:  15px;
  background: tomato;
  position: relative;
}
  .pulse-css:before,
  .pulse-css:after {
    content: "";
    width: 30px;
   height:  30px;
    border-radius:  15px;
    background-color: tomato;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    margin: auto;
    transform: scale(0.5);
    transform-origin: center center;
    animation: pulse-me 3s linear infinite;
  }
  .pulse-css:after {
    animation-delay: 2s;
  }


@keyframes pulse-me {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  50% {
    opacity: 0.1;
  }
  70% {
    opacity: 0.09;
  }
  100% {
    transform: scale(5);
    opacity: 0;
  }
}

    /* ]]> */
  </style>
  
      <circle class="circle first-circle" fill="#FF6347" cx="25" cy="25" r="25"></circle>
      <circle class="circle second-circle" fill="#FF6347" cx="25" cy="25" r="25"></circle>
      <circle class="circle third-circle" fill="#FF6347" cx="25" cy="25" r="25"></circle>
      <circle class="circle" fill="#FF6347" cx="25" cy="25" r="25"></circle>
    </svg>
  </div>
</div>