Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

css have a background color, text and an image in the same div

css have a background color, text and an image in the same div

Problem

So I have a box where I need to display some text, have a red Background Color and also have an image at the right of the box.

The idea is that the text should be given priority and Background color should still be red.

Here is an example but it overrides the background color:

.test {
  background-color: #e64e56;;
  box-shadow: 3px 3px 5px darkGray;
  color: white;
  background: url(http://thumb10.shutterstock.com/thumb_small/536008/103572833/stock-photo-small-flower-isolated-on-white-background-103572833.jpg) no-repeat top right;

}

http://jsbin.com/axohoc/1/edit

Problem courtesy of: newbie

Solution

Do you mean this?

.test {
  box-shadow: 3px 3px 5px darkGray;
  color: white;
  background: #e64e56 url(http://thumb10.shutterstock.com/thumb_small/536008/103572833/stock-photo-small-flower-isolated-on-white-background-103572833.jpg) no-repeat top right;
}

You can either define background-color, background-image, background-repeat and background-position separately, or use the shortcut background. When using the latter, it will overwrite the specific rules you have set, in this case background-color

Here is the example, edited http://jsbin.com/axohoc/7/edit

Here you can read up on the specifics of the shorthand property, as well as the different specific background properties: http://www.w3schools.com/css/css_background.asp

Solution courtesy of: maartenmachiels

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

css have a background color, text and an image in the same div

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×