Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using gradient but without mixing color

I don't know if that is a stupid question or something like that but i want a div to be filled certain percent by one color and remaining part by other.

And the gradient property

.div{
     background: linear-gradient(to right, #000 50%, #fff 50%);
}

Results into enter image description here

.div{
     background: linear-gradient(to right, #000 28%, #fff 72%);
}

And this results into enter image description here

i want to get the white and black not to mix and be seperated on all percentages.

like image 958
Suman KC Avatar asked Mar 18 '15 07:03

Suman KC


People also ask

Can I use linear gradient in background color?

Because <gradient> s belong to the <image> data type, they can only be used where <image> s can be used. For this reason, linear-gradient() won't work on background-color and other properties that use the <color> data type.

What is the required number of colors to produce a gradient effect?

To create the most basic type of gradient, all you need is to specify two colors. These are called color stops. You must have at least two, but you can have as many as you want.

How do I add color to a gradient image?

On your image, position the pointer where you would like the gradient to begin. Click and drag over the image in the direction you would like the gradient to follow. Release the mouse button. The gradient is applied to the entire layer.


4 Answers

try this

.div{
    background: -webkit-linear-gradient(left, black 50%, white 0%);
    background: -moz-linear-gradient(left, black 50%, white 0%);
    background: -ms-linear-gradient(left, black 50%, white 0%);
    background: linear-gradient(left, black 50%, white 0%);
}
like image 168
GaurabDahal Avatar answered Oct 03 '22 03:10

GaurabDahal


Why do you want to use gradient in first place if you dont want them to mix?

Anyway this is working:

div{
     height: 200px;
     background: -moz-linear-gradient(left, white 50%, black 0%);
     background: -linear-gradient(left, white 50%, black 0%);
     background: -webkit-linear-gradient(left, white 50%, black 0%);
}

you can put any value for white. It wont mix.

like image 37
Sushovan Avatar answered Oct 03 '22 03:10

Sushovan


When you did:

background: linear-gradient(to right, #000 28%, #fff 72%);

it means: Black (#000) from 0% to 28%, then start a gradient to white (#fff) until reach 72% and after this gradient, use white until the end.

So you can use:

background: linear-gradient(to right, #000 28%, #fff 28%);

This way you'll get: black from 0 to 28%, a gradient from 28% to 28% (it means, no gradient), and white from 28% to the end. So you'll get only back and white, without the gradient between them.

like image 32
Pedro Leite Avatar answered Oct 03 '22 03:10

Pedro Leite


do you mean :

div{
     background: linear-gradient(to right, #000 28%, transparent 28%, transparent 72%,#fff 72%);
  color:green
}
body {
  background:yellow
    }
<div> lorem ipsum blabla lorem ipsum blabla lorem ipsum blabla lorem ipsum blabla</div> 
like image 35
G-Cyrillus Avatar answered Oct 03 '22 02:10

G-Cyrillus