Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I apply multiple background colors with CSS3?

Tags:

css

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?

like image 762
Dipil Avatar asked Jun 23 '11 16:06

Dipil


People also ask

How do you add multiple background colors in CSS?

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.

How do I use two colors in CSS?

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.

How do I make multiple background colors in HTML?

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.

Does CSS3 allows you to use several background images for an element select one Otrue Ofalse?

CSS3 allows you to use several background images for an element.


1 Answers

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;  }
like image 151
Steven Lizarazo Avatar answered Oct 01 '22 00:10

Steven Lizarazo