Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to color a div half blue, half yellow?

Please, help me to find the easiest way to achieve this result with just one single div?

<div></div>

enter image description here

like image 416
TSR Avatar asked Sep 28 '16 06:09

TSR


People also ask

How do you add a half background color in HTML?

You can apply a background color to the html element, and then apply a background-image to the body element and use the background-size property to set it to 50% of the page width. This results in a similar effect, though would really only be used over gradients if you happen to be using an image or two.

Can div have color?

With Hexadecimal values, you can set a background color for a div or any other element with a total of 6 characters.


2 Answers

You can do this:

Here is the JSFiddle demo

Snippet Example

 div{
    	width:400px;
    	height:350px;
    	background: linear-gradient(to right, blue 50%, yellow 50%);
    }
<div></div>
like image 145
Ahs N Avatar answered Sep 23 '22 23:09

Ahs N


Try this code:

div {
  height: 200px;
  width: 400px;

background: blue; /* For browsers that do not support gradients */
  background: -webkit-linear-gradient(left, blue 50% , yellow 50%); /* For Safari 5.1 to 6.0 */
  background: -o-linear-gradient(right, blue 50%, yellow 50%); /* For Opera 11.1 to 12.0 */
  background: -moz-linear-gradient(right, blue 50%, yellow 50%); /* For Firefox 3.6 to 15 */
  background: linear-gradient(to right, blue 50% , yellow 50%); /* Standard syntax */
  }
<div></div>
like image 36
Jainam Avatar answered Sep 23 '22 23:09

Jainam