简体   繁体   中英

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>

在此处输入图片说明

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>

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>

Here you go.

 div { width: 400px; height: 200px; background:yellow; } div::after { width:50%; height:100%; content:""; background: blue; display:inline-block; }
 <div> </div>

html:

<div class="blue_yellow"></div>

css:

.blue_yellow {
background: linear-gradient(to left, blue 50%, yellow 50%);
}
    #leftHalf {
   background-color: blue;
   width: 50%;
   position: absolute;
   left: 0px;
   height: 100%;
}

#rightHalf {
   background-color: yellow;
   width: 50%;
   position: absolute;
   right: 0px;
   height: 100%;
}

Try with above CSS code

**Try This**
.container{
                height:120px;
                width:120px;
                border-radius:50%;
                background: linear-gradient(to right, rgb(183,88,206) 50%, rgb(170,61,200) 50%);
                transform: rotateY(0deg) rotate(45deg);
            }

 <html> <head> <title>Test Box</title> <style> .container{ height:120px; width:120px; border-radius:50%; background: linear-gradient(to right, rgb(183,88,206) 50%, rgb(170,61,200) 50%); transform: rotateY(0deg) rotate(45deg); } </style> </head> <body> <div class="container"> </div> </body> </html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM