html - 将 svg 居中对齐到具有灰色背景的按钮

标签 html css button svg styling

我有一个带有图像的按钮,我想将其对齐到中心。我希望按钮具有灰色背景。

HTML:

 <button type="submit" data-target="#modal">
            <img className="rainbow" role="presentation" />
 </button>

CSS:

.rainbow {
  background: url("/static/icons/arrow.svg") no- repeat center;
  border: none;
  cursor:pointer;
  overflow: hidden;
  outline:none;
  height: 53px; 
  width: 50px;  
  background-color: $welcome-gray-1;
}

final_image_button

icon_center_aligned

最佳答案

您不需要内联图像,您需要将背景应用到按钮元素。

button {
  background: #000 url("/static/icons/arrow.svg") no-repeat center;
  border: none;
  cursor: pointer;
  overflow: hidden;
  outline: none;
  height: 53px;
  width: 50px;
}
<button type="submit" data-target="#modal" />

关于html - 将 svg 居中对齐到具有灰色背景的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54839675/

相关文章:

html - 为什么 flex 元素不缩小过去的内容大小?

html - hInserting line-break into XML 以便它出现在 VB.NET 中的 XSL 呈现之后

html - CSS/HTML 文本在悬停时移动并显示附加文本

css - 是否可以使图像的高度响应(没有 js)?

javascript - 如何为谷歌字体做回退?

jquery - 单击按钮后,tinyMCE 光标位于文本中间

html - 为什么我的响应式背景图像在图像底部留下空白?

html - 设置 div 的宽度直到浏览器端

css - 单击引导按钮后删除颜色更改

ios - 当我的应用程序处于后台时在 iOS 上捕获硬件按钮