I know how to specify multiple background images using CSS3 and modify how they are displayed using different options.
Currently I have a <div>
, which needs to have a different color for about 30% of the width on the left side:
div#content { background: url("./gray.png") repeat-y, white; background-size: 30%; }
Instead of loading the image which is totally gray, how can I do this specifying the color, and without additional <div>
s?
CSS allows you to add multiple background images for an element, through the background-image property. The different background images are separated by commas, and the images are stacked on top of each other, where the first image is closest to the viewer.
To use more than 2 colors (because why not), put the powerful rgba() to use and use 2 gradient parameters. Here's an example with the background property holding an image and masking some portion of the image with a gradient of orange and transparent.
To add background color in HTML, use the CSS background-color property. Set it to the color name or code you want and place it inside a style attribute. Then add this style attribute to an HTML element, like a table, heading, div, or span tag.
CSS3 allows you to use several background images for an element.
Yes its possible! and you can use as many colors and images as you desire, here is the right way:
body{ /* Its, very important to set the background repeat to: no-repeat */ background-repeat:no-repeat; background-image: /* 1) An image */ url(http://lorempixel.com/640/100/nature/John3-16/), /* 2) Gradient */ linear-gradient(to right, RGB(0, 0, 0), RGB(255, 255, 255)), /* 3) Color(using gradient) */ linear-gradient(to right, RGB(110, 175, 233), RGB(110, 175, 233)); background-position: /* 1) Image position */ 0 0, /* 2) Gradient position */ 0 100px, /* 3) Color position */ 0 130px; background-size: /* 1) Image size */ 640px 100px, /* 2) Gradient size */ 100% 30px, /* 3) Color size */ 100% 30px; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With