开发者

how to write a css for background

I have a transparent logo for wh开发者_运维知识库ich i want to apply a background color how can i do so using css?


Simply use background-color on your element as such:

<img style="background-color: #F00;" src="my_transparent_logo.png" />

If you do not want to do it inline, you can assign it an ID (or class) like such:

<img id="logo" src="my_transparent_logo.png" />

and in your external CSS file do the following:

#logo {
  background-color: #F00;
}


You can use

background-color

See Background properties


Assuming an element with an id attribute with the unique value "logo",

#logo { background-image: url("foo"); background-color: #F00; }


Here is another resource for when you are applying background properties through css: http://www.w3schools.com/css/css_background.asp

my thought though is that if you want the image to have a background color, this could defeat the purpose of using a .png so it might be better to convert the .png into a .jpg with the background color added into the image itself. Then you don't have to worry about browser compatibility with transparency --- of coarse it just depends on what your goal is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜