I'm trying to achieve this gradient. What I don't understand is the curvature of it and I'm not sure on how to replicate it:
What I have so far:
and my code for the gradient:
radial-gradient(at top left,#629a92 36%,#02d2a0 67%, #fff 11%)
However I'm not sure how this gets stretched to the end of the screen. I haven't used radial-gradient much before so I feel like I'm missing something. Any help would be greatly appreciated. Thank you.
You need to also adjust background-size of the gradient:
body {
height:100vh;
margin:0;
background-image:radial-gradient(at top left,#629a92 36%,#02d2a0 67%, transparent 67.5%);
background-size:120% 100%;
background-repeat:no-repeat;
}
Or adjust the radius:
body {
height:100vh;
margin:0;
background-image:radial-gradient(120% 100% at top left,#629a92 61%,#02d2a0 92%, transparent 92.5%);
background-repeat:no-repeat;
}
UPDATE
If it's a linear-gradient inside a curved shape you can try to use multiple background. The idea is to create the linear-gradient and above it you add the a radial-gradient with transparent color to be able to see the first gradient.
body {
height:100vh;
margin:0;
background-image:
radial-gradient(120% 100% at top left,transparent 92%, #fff 92.5%),
linear-gradient(135deg, #51a595 0%, #3fcfa2 100%);
}
If you look carefully it is not a radial gradient. It is a linear gradient inside a radial shape. If I were you, I would do a SVG shape—mine is just for using as example—and apply it to the gradient.
Like this:
body {
margin: 0;
}
svg {
width: 0;
height: 0;
display: block;
}
.main {
width: 100%;
height: 100vh;
position: relative;
}
.main:before {
content: '';
position: absolute;
overflow: hidden;
width: 100%;
height: 100%;
background: #51a595;
background: linear-gradient(135deg, #51a595 0%, #3fcfa2 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#51a595', endColorstr='#54bb9b',GradientType=1 );
-webkit-clip-path: url("#mask");
clip-path: url("#mask");
}
<svg>
<defs>
<clipPath id="mask">
<ellipse cx="0" cy="-1400" rx="2200" ry="1500"></ellipse>
</clipPath>
</defs>
</svg>
<div class="main"></div>
Looking at radial-gradient on mdn, it can take 2 percentages before the at top left for its size. We can make the first larger than 100% so it will extend beyond the screen on the x axis and put the second percent to 100% so it ends at the bottom.
radial-gradient(
200% 100% at top left,
#629a92 36%,
#02d2a0 67%,
#fff 11%
);
This should result in what you are looking for
.head {
width: 100%;
height: 200px;
background: radial-gradient(
200% 100% at top left,
#629a92 36%,
#02d2a0 67%,
#fff 11%
)
}
.body {
height: 200px;
width: 100%;
}
<div class="head"></div>
<div class="body"></div>
Related
If I have this:
https://codepen.io/anon/pen/MveydB
body {
width: 100vh; height: 100vh;
background-image: radial-gradient(circle closest-side, #00bffb, rgba(0, 0, 0, 1));
}
How I can have something like this instead?:
It's impossible to edit HTML in this case too, because it's a theme for Linux.
Cover with a linear gradient
Paint a half transparent, half black linear gradient on top of it.
.bg {
width: 100vh;
height: 100vh;
background: linear-gradient(to bottom, transparent 50%, black 50%),
radial-gradient(circle closest-side, #00bffb, black);
}
body {
margin: 0;
}
<div class="bg"></div>
Or
Cover with a pseudo element
If you want to create a radial gradient with two halves of different color, you can use a pseudo element with half the height of the parent.
.bg {
position: relative;
width: 100vh;
height: 100vh;
background: radial-gradient(circle closest-side, yellow, black);
}
.bg::before {
display: block;
position: absolute;
top: 0;
left: 0;
width: 100vh;
height: 50%;
background: radial-gradient(circle closest-side, #00bffb, black);
background-size: 100% 200%; /** we need to compensate for the 50% height **/
content: '';
}
body {
margin: 0;
}
<div class="bg"></div>
Set the gradient on half of the container with background-size: 100% 50%,
Position the gradient circle so that only its top half is visible with background-image: radial-gradient(circle 50vh at 50% 100%, #00bffb, #0000);
Explanation:
circle 50vh sets the gradient radius to half the size of the container (you need to use a fixed size, thus 50vh, or 200px if your container was 400px tall — % won't work, sadly)
at 50% 100% sets the gradient center in the middle of the bottom edge of the background box.
body {
width: 100vh;
height: 100vh;
background-color: #000;
background-image: radial-gradient(circle 50vh at 50% 100%, #00bffb, #0000);
background-size: 100% 50%;
background-repeat: no-repeat;
}
https://codepen.io/hyvyys/pen/xxKRGwP
According to this answer, this should work:
#shop {
background-image: url('../images/tilecovers/shop.jpg'),
linear-gradient(
135deg,
rgba(228,245,252,0.18) 0%,
rgba(191,232,249,0.2) 49%,
rgba(191,232,249,0.21) 65%,
rgba(159,216,239,0.21) 73%,
rgba(82,189,236,0.22) 100%);
}
It doesn't work though, only the image is visible.
After a few refreshes, I noticed the gradient is loading first, then the image on top of it. How can I make the translucent gradient on top of the background image?
Not sure about cross browser support but one option is using the background-blend-mode property like so:
.shop {
background-image: url('https://placeholdit.co//i/500x250?bg=111111'),
linear-gradient(
135deg,
rgba(228,245,252,0.18) 0%,
rgba(191,232,249,0.2) 49%,
rgba(191,232,249,0.21) 65%,
rgba(159,216,239,0.21) 73%,
rgba(82,189,236,0.22) 100%);
background-blend-mode: overlay;
width: 500px;
height: 250px;
}
.shop-no-gradient {
background-image: url('https://placeholdit.co//i/500x250?bg=111111');
width: 500px;
height: 250px;
}
<div class="shop"></div>
<br>
<div class="shop-no-gradient"></div>
Use :before to apply the filter.
Like so:
#shop {
width: 350px;
height: 150px;
background: url("http://via.placeholder.com/350x150") center center no-repeat;
}
#shop:before {
width: 350px;
height: 150px;
content: '';
position: absolute;
background-image: linear-gradient(
135deg,
rgba(228,245,252,0.18) 0%,
rgba(191,232,249,0.2) 49%,
rgba(191,232,249,0.21) 65%,
rgba(159,216,239,0.21) 73%,
rgba(82,189,236,0.22) 100%
);
}
<div id="shop">
</div>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How to create the 3 vertical lines as in the following image using CSS?
This is pretty easy to create with linear-gradient background images and we don't need more than one div element to create this with gradients. All we need is a couple of gradient images.
Below is an explanation of how the shape was achieved:
One linear gradient image which is 85% the size of the container in the X-axis and 75% the size of the container in the Y-axis is used to create the large white portion and it is positioned on left of the container.
One more linear gradient image which is 15% of the size of the container in X-axis and 15% of the container's size in Y-axis is used to create the three stripes at the end. The stripes are created by splitting the gradient into colored and transparent portions. The colored portions are sized equally to produce a stripe like effect.
Note: The third bar in the image in question seems to be a little lower than the others, I am assuming this to be an error in the image. If it is not, it could still be achieved with the below approach.
body {
background: yellow;
}
.shape {
height: 100px;
width: 400px;
transform: skew(-30deg);
transform-origin: left bottom;
background-image: linear-gradient(to left, rgba(255,255,255,0.5) 25%, transparent 25%, transparent 33%, rgba(255,255,255,0.75) 33%, rgba(255,255,255,0.5) 60%, transparent 60%, transparent 66%, rgba(255,255,255,1) 66%, rgba(255,255,255,0.75) 93%, transparent 93%), linear-gradient(white, white);
background-size: 15% 100%, 85% 75%;
background-position: 100% 100%, 0% 0%;
background-repeat: no-repeat;
}
<div class='shape'></div>
You could also make use of SVG path elements to create this shape.
.shape {
position: relative;
height: 100px;
width: 300px;
}
.shape svg {
position: absolute;
height: 100%;
width: 100%;
top: 0px;
left: 0px;
}
.shape svg path#white-bar {
fill: rgba(255, 255, 255, 1);
}
.shape svg path#translucent-bar-1 {
fill: rgba(255, 255, 255, 0.75);
}
.shape svg path#translucent-bar-2 {
fill: rgba(255, 255, 255, 0.5);
}
body {
background: yellow;
}
<div class='shape'>
<svg viewBox='0 0 300 100'>
<path d='M0,75 25,0 240,0, 221.5,75z M245,0 220,100 235,100 260,0' id='white-bar' />
<path d='M265,0 240,100 255,100 280,0' id='translucent-bar-1' />
<path d='M285,0 260,100 275,100 300,0' id='translucent-bar-2' />
</svg>
</div>
Note: It may well be possible to create this using a single path element and an angled gradient fill but I am not that good with SVG.
I did a fiddle.
trick is you need to transform the figure and use vertical-align property.
-webkit-transform: skew(20deg);
vertical-align: text-top;
Tweaking #Siddarth's code, this might be more suited to the above given image:
div{
display:inline-block;
vertical-align: text-top;
-webkit-transform: skew(-20deg);
-moz-transform: skew(-20deg);
-o-transform: skew(-20deg);
background: white;
}
.one{
width: 450px;
height: 100px;
}
div:not(.one){
margin-left:0px;
width: 20px;
height: 200px;
}
.two{
opacity:.8;
}
.three{
opacity:.6;
}
.four{
opacity:.4;
}
body {
background-color: rgb(255, 210, 2);
}
<body>
<div class="one">
</div>
<div class="two">
</div>
<div class="three">
</div>
<div class="four">
</div>
</body>
When i create background gradient like this:
background: radial-gradient(ellipse at center, #ffffff 0%,#ffffff 59%,#ededed 100%);
I get ellipse that is inside the div, and conform to shape of div. So if div is large in height then ellipse would be stretched vertically. If div is a square then ellipse would be like a circle. That's fine, i want to control height of ellipse.
The exact question can be addressed by combining the last 2 answers: circle gradient and adjusting the background size.
Something like this:
div {
width: 300px;
height: 100px;
background: radial-gradient(circle, white 0%, red 50%, black 100%);
background-size: 100% 200%;
background-position: 0% 50%;
}
<div></div>
I find it less of a hassle than nested divs, and by playing with the background-position and size values, you can get some pretty cool effects!
Use a div with overflow set to hidden, and a div inside of it absolutely positioned with a fixed height.
#outer {
height: 100px;
overflow: hidden;
position: relative;
width: 200px;
}
#inner {
background: radial-gradient(ellipse at center, #1e5799 0%, #2989d8 50%, #207cca 51%, #7db9e8 100%);
bottom: 0;
height: 150px;
position: absolute;
width: 200px;
}
<div id="outer">
<div id="inner"></div>
</div>
You can play with the background dimensions and position:
div {
width: 300px;
height: 100px;
background: radial-gradient(ellipse at center, white 0%, red 100%);
background-size: 100% 200%;
background-position: 0% 50%;
}
demo
You can try circle instead of ellipse:
Demo on dabblet
.rect2 {
width: 600px;
height: 100px;
line-height: 100px;
text-align: center;
background: radial-gradient(circle, #ffffff 0%, #ffffff 59%, #dcdcdc 100%);
}
What I am trying to achieve is that I have gradient on the div background, and I am trying to add a background image over the gradient(image is just a pattern) but either only gradient is being applied or only the pattern, not both
I get a white background with this code:
#box{
padding:50px;
background:linear-gradient(45deg, #A50F06 0%, #51A351 100%) repeat scroll 0% 0% transparent url('bs-docs-masthead-pattern.png') repeat scroll center center transparent;
}
only gradient with this:
#box{
background:linear-gradient(45deg, #A50F06 0%, #51A351 100%) repeat scroll 0% 0%
}
#box:after{
background: transparent url('pattern.png') repeat scroll center center transparent;
}
what m I doing wrong?
Update your CSS like below.
#box{
background:url('https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSXwTmM2R_vmBHFpn720_8bGOaegnP5Kawh0wb4JggN5rUALGwGvw') no-repeat center center, linear-gradient(45deg, #A50F06 0%, #51A351 100%) repeat scroll 0% 0%;
height:500px;
}
FIDDLE DEMO
add content:"" in pseudo element
* {
margin: 0;
padding: 0;
}
html,
body {
width: 100%;
height: 100%;
}
#box {
background: linear-gradient(45deg, #A50F06 0%, #51A351 100%) repeat scroll 0% 0%;
width: 100%;
height: 100%;
}
#box::after {
content: "";
background: url('http://s28.postimg.org/rfznph7ul/pattern.png');
width: 100%;
height: 100%;
display: block;
}
<div id="box"></div>