简体   繁体   中英

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. How does one avoid this in CSS?

Button with svg background:

#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:

#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.

#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

#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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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