简体   繁体   English

SVG背景覆盖CSS中的按钮颜色

[英]SVG background covers button color in CSS

I have an svg image that I would like to be contained inside of a white button, however, inserting it into the background in CSS covers the white color of the button completely. 我有一个svg图像,我想将其包含在白色按钮内,但是,将其插入CSS的背景中会完全覆盖按钮的白色。 How does one avoid this in CSS? 如何在CSS中避免这种情况?

Button with svg background: 带有svg背景的按钮:

#rack-button {
    position: absolute;
    background: url('simple_rack.svg') no-repeat top left;
    background-size: contain;
    display: inline-block;
    width:  35px;
    height: 35px;
    left: 10%;
    border-radius: 5px;
    color:#fff;
}

在此处输入图片说明

Button without svg background: 没有svg背景的按钮:

#rack-button {
    position: absolute;
    width:  35px;
    height: 35px;
    left: 10%;
    border-radius: 5px;
    color:#fff;
}

在此处输入图片说明

Your initial button CSS has no background-color stated so this must be stated somewhere else in your CSS. 您的初始按钮CSS没有说明background-color因此必须在CSS的其他地方说明。

#rack-button {
  position: absolute;
  width:  35px;
  height: 35px;
  left: 10%;
  border-radius: 5px;
  color:#fff;
}

When you added the image background you overrode the original background color and substituted a transparent image, so the body background shows through 添加图像背景时,您会覆盖原始背景色并替换为透明图像,因此body背景会通过

#rack-button {
  position: absolute;
   background: url('simple_rack.svg') no-repeat top left;
   background-size: contain;
   display: inline-block;
  width:  35px;
  height: 35px;
  left: 10%;
  border-radius: 5px;
  color:#fff;
}

You just need to add the background color back 您只需要添加背景色

#rack-button {
   background: white url('simple_rack.svg') no-repeat top left;
}

or 要么

#rack-button {
   background: url('simple_rack.svg') no-repeat top left;
   background-color:white;
}

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

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