Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple vertical background colors in CSS3

Problem:

Trying to create a solution that would allow me to have five multiple background colors that fill out a webpage regardless of width. I have managed to do this with 5 div tags but I wonder if it's possible to do this completely using CSS3?

The outcome I would like is:

enter image description here

I have searched Stackoverflow and the web without any results, or I am simply very bad at searching.

like image 963
kexxcream Avatar asked Oct 04 '14 19:10

kexxcream


People also ask

How do I have 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.

Can we use two or more colors as background colors?

Essentially, the background property can hold two contents one over the other: 2 gradients, 2 images or you can mix-and-match any of those. To use more than 2 colors (because why not), put the powerful rgba() to use and use 2 gradient parameters.

How do I put two 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.


1 Answers

You could use linear-gradients to achieve this.

Example Here

html, body {
    height: 100%;
}
body {
    background-image: linear-gradient(90deg,
        #F6D6A8 20%,
        #F5BA55 20%, #F5BA55 40%,
        #F09741 40%, #F09741 60%,
        #327AB2 60%, #327AB2 80%,
        #3A94F6 80%);
}

Just add vendor prefixes for additional browser support

body {
    background: -moz-linear-gradient(90deg, #F6D6A8 20%, #F5BA55 20%, #F5BA55 40%, #F09741 40%, #F09741 60%, #327AB2 60%, #327AB2 80%, #3A94F6 80%);
    background: -webkit-linear-gradient(90deg, #F6D6A8 20%, #F5BA55 20%, #F5BA55 40%, #F09741 40%, #F09741 60%, #327AB2 60%, #327AB2 80%, #3A94F6 80%);
    background: linear-gradient(90deg, #F6D6A8 20%, #F5BA55 20%, #F5BA55 40%, #F09741 40%, #F09741 60%, #327AB2 60%, #327AB2 80%, #3A94F6 80%);
}

Browser support can be found here.

like image 103
Josh Crozier Avatar answered Sep 29 '22 17:09

Josh Crozier