Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background color 50% one color and 50% another color

Inside a div I want to put a background color in the first 50% of it's width, and another color the other 50% of it's width. Ideally On resize I want it to adjust seamlessly without any artifacts or jittery effects.

Ideally I want to avoid using other divs inside the code as I'm working with existing HTML that is difficult to change - really looking for a 100% CSS solution.

I'm looking for something like this (I mocked this up with Fireworks): enter image description here

like image 655
fakeguybrushthreepwood Avatar asked Jan 17 '14 03:01

fakeguybrushthreepwood


People also ask

How do I add two 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 make the background of two 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.


Video Answer


1 Answers

you can use something like, but based upong the browsers you have to support, it may not work across all of them.

background: linear-gradient(to left, #ff0000 50%, #0000ff 50%);
like image 193
hosker Avatar answered Sep 24 '22 09:09

hosker