Html 响应SVG矩形

Html 响应SVG矩形,html,css,svg,Html,Css,Svg,我是svg按钮动画的一个很好的例子,但是按钮的大小是静态的-320px x 60px。我希望按钮具有响应性——它是svg矩形,但我很难做到这一点 HTML: 我已经读了一篇关于这个问题的文章,我遵循了内联svg的所有步骤,但是我想我遗漏了一些东西。 您能帮我使SVG矩形响应吗?将preserveAspectRatio=“none”属性添加到SVG中将preserveAspectRatio=“none”属性添加到SVG中 <div class="svg-wrapper"> <

我是svg按钮动画的一个很好的例子,但是按钮的大小是静态的-320px x 60px。我希望按钮具有响应性——它是svg矩形,但我很难做到这一点

HTML:

我已经读了一篇关于这个问题的文章,我遵循了内联svg的所有步骤,但是我想我遗漏了一些东西。
您能帮我使SVG矩形响应吗?

将preserveAspectRatio=“none”属性添加到SVG中

将preserveAspectRatio=“none”属性添加到SVG中

<div class="svg-wrapper">
  <svg class="svg-responsive" viewBox="0 0 320 60" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">
    <rect class="shape" width="100%" height="100%"/>
  </svg>
  <div class="text">HOVER</div>
</div>
.svg-wrapper {
  border: 1px solid red;
  position: relative;

  height: 0;
  padding-top: 16.6%;
}
svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.shape {
  width: 100%;
  height: 100%;
  fill: salmon;
  stroke-dasharray: 140 540;
  stroke-dashoffset: -474;
  stroke-width: 8px;
  stroke: #19f6e8;
}

.text {
  color: #fff;
  font-family: "Roboto Condensed";
  font-size: 22px;
  letter-spacing: 8px;
  line-height: 32px;
  position: relative;
  top: -48px;
}

@keyframes draw {
  0% {
    stroke-dasharray: 140 540;
    stroke-dashoffset: -474;
    stroke-width: 8px;
  }
  100% {
    stroke-dasharray: 760;
    stroke-dashoffset: 0;
    stroke-width: 2px;
  }
}

.svg-wrapper:hover .shape {
  -webkit-animation: 0.5s draw linear forwards;
  animation: 0.5s draw linear forwards;
}