So I wanted to make a diamond with an image in it but the image will deform. I want to make it so that it's horizontal (normal) and filling the diamond.
The code I made.
.diamond {
width: 300px;
height: 300px;
border: 3px solid white;
outline: 2px solid black;
outline-offset: 20px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) rotate(67.5deg) skewX(45deg) scaleY(0.70711);
overflow: hidden;
}
.diamond-image {
background-image: url("https://images7.alphacoders.com/108/1082408.png");
background-size: cover;
position: absolute;
height: 100%;
width: 140%;
top: 0px;
left: 0px;
transform-origin: top bottom;
}
html{
height: 100%;
}
body{
background: rgb(224,215,215);
background: radial-gradient(circle, rgba(224,215,215,1) 0%, rgba(144,144,144,1) 100%);
}
<div class="diamond">
<div class="diamond-image"></div>
</div>
It would probably be complex to invert the transformation. I would build this differently without transformation.
You can simply control the shape by adjusting the width/height and the CSS variables
html{
min-height: 100%;
background: radial-gradient(circle, rgba(224,215,215,1) 0%, rgba(144,144,144,1) 100%);
}
.box {
--d:15px; /* gap between border and outline*/
--b1:3px; /* width of outline (black)*/
--b2:3px; /* width of border (white) */
--g1:transparent calc(48% - var(--d) - var(--b1) - var(--b2)) ,
#fff calc(49% - var(--d) - var(--b1) - var(--b2)) calc(49% - var(--b1)),
#000 calc(50% - var(--b1));
--g2:#fff calc(48.5% - var(--d) - var(--b1) - var(--b2)) calc(48.5% - var(--d) - var(--b1)),
transparent calc(49% - var(--d) - var(--b1)) calc(49% - var(--b1)),
#fff calc(49.5% - var(--b1)) 49.5%,
transparent 50%;
width:200px;
height:400px;
display:inline-block;
vertical-align:top;
background:
linear-gradient(to top right,var(--g1)) top right / 50% 50%,
linear-gradient(to top left ,var(--g1)) top left / 50% 50%,
linear-gradient(to bottom right,var(--g1)) bottom right / 50% 50%,
linear-gradient(to bottom left ,var(--g1)) bottom left / 50% 50%,
url(https://picsum.photos/id/1074/800/800) center/cover;
background-repeat:no-repeat;
-webkit-mask:
linear-gradient(to top right,var(--g2)) top right,
linear-gradient(to top left ,var(--g2)) top left,
linear-gradient(to bottom right,var(--g2)) bottom right,
linear-gradient(to bottom left ,var(--g2)) bottom left;
-webkit-mask-size:50% 50%;
-webkit-mask-repeat:no-repeat;
mask:
linear-gradient(to top right,var(--g2)) top right,
linear-gradient(to top left ,var(--g2)) top left,
linear-gradient(to bottom right,var(--g2)) bottom right,
linear-gradient(to bottom left ,var(--g2)) bottom left;
mask-size:50% 50%;
mask-repeat:no-repeat;
}
<div class="box"></div>
<div class="box" style="width:300px;--b1:5px;--d:20px"></div>
<div class="box" style="height:200px;--b2:5px;--d:5px"></div>
Related
I have to create image like this using CSS:-
If not possible then how can I use this with minimum image size? Like in below code I have used two images but this is also not working...
<div style="background:url('https://i.stack.imgur.com/veeS8.png') no-repeat top center, url('https://i.stack.imgur.com/2i7ed.png') repeat-y top 50px center; widhth:100%; height:800px; background-size:100%;">
</div>
Also possible with masking without using image. This is more flexible. You can control easily the slope by changing the variable.
.container {
--slope: 100px;
width: 100%;
height: 500px;
--mask: radial-gradient(farthest-side, #000 99%, transparent 100%) 50% 0 / 150% calc(var(--slope) * 2) no-repeat,
linear-gradient(#000, #000) 0 100% / 100% calc(100% - var(--slope)) no-repeat;
-webkit-mask: var(--mask);
mask: var(--mask);
background: linear-gradient(90deg, rgba(133, 132, 242, 1) 0%, rgba(35, 136, 253, 1) 50%, rgba(127, 237, 226, 1) 100%);
}
<div class='container'></div>
something like this would work:
div.cont:before {
content: '';
background-image: url(https://i.stack.imgur.com/2i7ed.png);
background-size: 100% auto;
position: absolute;
top: 44px;
left: 0;
right: 0;
bottom: 0;
}
<div class="cont" style="width: 100%;height:800px;background-image: url(https://i.stack.imgur.com/veeS8.png);background-size: 100% auto;background-repeat: no-repeat;position: relative;">
</div>
a trivial task using clip-path
.container {
height: 400px;
background: linear-gradient(90deg, rgba(133,132,242,1), rgba(35,136,253,1), rgba(127,237,226,1));
clip-path:ellipse(90% 100% at bottom); /* simply adjust the 90% */
}
<div class='container'></div>
To have the same curvature on resize use pixel value
.container {
height: 400px;
max-width:800px;
background: linear-gradient(90deg, rgba(133,132,242,1), rgba(35,136,253,1), rgba(127,237,226,1));
clip-path:ellipse(600px 100% at bottom);
}
<div class='container'></div>
.element {
width: 200px;
height: 200px;
border-radius: 100% 100% 0 0 / 20% 20% 0 0;
background-image: linear-gradient(to right, #8684F2 0%, #1BEEE3 100%);
}
You can use CSS Gradient to get this kind of result. You can also use some tools online to generate some gradients like this one:
https://cssgradient.io/
.container {
width: 500px;
height: 500px;
background: rgb(133,132,242);
background: linear-gradient(90deg, rgba(133,132,242,1) 0%, rgba(35,136,253,1) 50%, rgba(127,237,226,1) 100%);
}
<div class='container'>
</div>
I have a bit of a problem with creating a block with beveled edges, in addition I need a border to be beveled and slightly off the main block. The problem is that this block can be Reponsive according to the screen.
I do not know the exact way to do it, hope everyone helps.
This is what I do now
.box {
display: flex;
padding: 20px;
height: 200px;
width: 300px;
color: #ffffff;
background: red;
position: relative;
}
.box .edge {
width: 18px;
height: 10px;
background: #ffffff;
position: absolute;
}
.box .edge.top-left {
top: -4px;
left: -8px;
transform: rotate(-45deg);
}
.box .edge.top-right {
top: -4px;
right: -8px;
transform: rotate(45deg);
}
.box .edge.bottom-left {
bottom: -4px;
left: -8px;
transform: rotate(45deg);
}
.box .edge.bottom-right {
bottom: -4px;
right: -8px;
transform: rotate(-45deg);
}
<div class="box">
<div class="edge top-left"></div>
<div class="edge top-right"></div>
<div class="edge bottom-left"></div>
<div class="edge bottom-right"></div>
<div class="content">
content
</div>
</div>
Here is an idea based on this previous answer. Simply adjust the different variables to get the result you want:
.box {
--c:10px; /* the corner */
--b:3px; /* border thickness*/
--o:-10px,-15px; /* offset*/
--border-color:green;
--bg-color:red;
width: 200px;
height: 100px;
display:inline-block;
margin:30px;
position:relative;
z-index:0;
}
.box:before,
.box:after{
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
clip-path: polygon(var(--c) 0%, calc(100% - var(--c)) 0%, 100% var(--c), 100% calc(100% - var(--c)), calc(100% - var(--c)) 100%, var(--c) 100%, 0% calc(100% - var(--c)), 0% var(--c));
background:var(--bg-color);
}
.box:after {
--grad:transparent 49.5%,var(--border-color) 50%;
background:
linear-gradient(to top right ,var(--grad)) top right,
linear-gradient(to top left ,var(--grad)) top left,
linear-gradient(to bottom right,var(--grad)) bottom right,
linear-gradient(to bottom left ,var(--grad)) bottom left;
background-size:calc(var(--c) - var(--b)) calc(var(--c) - var(--b));
background-repeat:no-repeat;
border: var(--b) solid var(--border-color);
transform:translate(var(--o));
}
<div class='box'></div>
<div class='box' style="--c:40px;--b:2px;--o:10px,-20px;--border-color:blue;--bg-color:orange"></div>
Works with image too:
.box {
--c:10px; /* the corner */
--b:3px; /* border thickness*/
--o:-10px,-15px; /* offset*/
--border-color:green;
--bg-color:red;
width: 200px;
height: 100px;
display:inline-block;
margin:30px;
position:relative;
z-index:0;
}
.box:before,
.box:after{
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
clip-path: polygon(var(--c) 0%, calc(100% - var(--c)) 0%, 100% var(--c), 100% calc(100% - var(--c)), calc(100% - var(--c)) 100%, var(--c) 100%, 0% calc(100% - var(--c)), 0% var(--c));
background:url(https://picsum.photos/id/1069/800/800) center/cover;
}
.box:after {
--grad:transparent 49.5%,var(--border-color) 50%;
background:
linear-gradient(to top right ,var(--grad)) top right,
linear-gradient(to top left ,var(--grad)) top left,
linear-gradient(to bottom right,var(--grad)) bottom right,
linear-gradient(to bottom left ,var(--grad)) bottom left;
background-size:calc(var(--c) - var(--b)) calc(var(--c) - var(--b));
background-repeat:no-repeat;
border: var(--b) solid var(--border-color);
transform:translate(var(--o));
}
<div class='box'></div>
<div class='box' style="--c:40px;--b:2px;--o:10px,-20px;--border-color:blue;"></div>
You can use outline property to create border which can give create border off the main block using outline-offset property. And hide the overflow element at the corner side using overflow:hidden property.
For example:
.box{
outline:5px solid black;
outline-offset:5px;
overflow:hidden;
}
Hi i want effect like this on my div but only at the bottom:
What im doing right now is this:
.container {
width: 500px;
height: 150px;
background: #FDCA40;
}
.box {
width: 100%;
height: 100px;
background: #FE7448;
-webkit-mask: radial-gradient(circle 20px, transparent 97%, #fff 100%) top/50px 200%;
// not working:
// -webkit-mask: radial-gradient(circle 20px, #FE7448 97%, #FE7448 100%) top/50px 200%;
}
<div class="container">
<div class="box"></div>
</div>
Which property in mask allows me to give color to circle? Whole mask property is confusing to me.
You can do it like below:
.container {
width: 500px;
height: 150px;
background: #FDCA40;
}
.box {
height: 100px;
background: #FE7448;
-webkit-mask:
linear-gradient(#fff 0 0)
top/100% calc(100% - 20px) no-repeat,
radial-gradient(circle closest-side, #fff 97%,transparent 100%)
bottom/50px 40px space;
}
<div class="container">
<div class="box"></div>
</div>
Using CSS variables to easily manage it:
.container {
width: 500px;
height: 150px;
background: #FDCA40;
}
.box {
--r:20px; /* radius */
--d:10px; /* minimum distance between circles */
height: 100px;
background: #FE7448;
-webkit-mask:
linear-gradient(#fff 0 0)
top/100% calc(100% - var(--r)) no-repeat,
radial-gradient(circle closest-side, #fff 97%,transparent 100%)
bottom/calc(2*var(--r) + var(--d)) calc(2*var(--r)) space;
}
<div class="container">
<div class="box"></div>
</div>
<div class="container">
<div class="box" style="--r:30px;--d:0px;"></div>
</div>
I want to make a 0-100% responsive gauge with pure css, with a color gradient from green to red. I found some examples but couldn't get a gradient working right in any of them. After some testing I managed to get it kinda working. It's basically a background div with a linear gradient background, and a white foreground div with half transparent borders, using border-radius to make them round. When I rotate the foreground div it reveals or obscure parts of the gradient background div.
But I have this visual glitch that I don't know how to fix:
The white borders of the foreground div are not completely obscuring the gradient div.
This is my test code (it may contain unnecessary css rules from all the previous tests I did):
https://jsfiddle.net/fLtzrg3w/
HTML:
<div class="c">
<div class="go">
<div class="g"></div>
<div class="gbg"></div>
</div>
</div>
CSS:
.c{
position: relative;
float:left;
text-align: center;
width: 50%;
padding: 25% 5px 0 5px;
height: 1rem;
overflow:hidden;
}
.go{
position: relative;
width: 100%;
overflow: hidden;
padding-top:100%;
margin-top: -50%;
}
.g{
position: absolute;
top: 0; left: 0;
width: 100%; height: 100%;
border-radius: 50%;
box-sizing: border-box;
border: 40px solid transparent;
border-bottom-color: #fff;
border-right-color: #fff;
transform: rotate(20deg);
background: white;
background-clip: padding-box;
z-index: 2;
}
.gbg{
position: absolute;
top: 0; left: 0;
width: 100%; height: 100%;
border-radius: 50%;
box-sizing: border-box;
background: linear-gradient(to right, green 0%, yellow 50%, red 100%);
z-index: 1;
}
How can I make the white div completely cover the background gradient div?
I would do this differently using multiple background:
.box {
width:250px;
border-radius:500px 500px 0 0;
background:
/* a linear gradient to control the progress. Adjust the angle from 0deg to 180deg*/
linear-gradient(160deg,transparent 50%,#fff 0) top/100% 200%,
/* a radial gradient to show only a part of the gradient (20px here)*/
radial-gradient(farthest-side at bottom,#fff calc(100% - 20px),transparent 0),
/* the main gradient */
linear-gradient(to right, green , yellow , red);
}
.box::before {
content:"";
display:block;
padding-top:50%;
}
<div class="box"></div>
That you can optimize with CSS variables:
.box {
--p:160deg;
--b:20px;
width:250px;
display:inline-block;
border-radius:500px 500px 0 0;
background:
/* a linear gradient to control the progress. Adjust the angle from 0deg to 180deg*/
linear-gradient(var(--p),transparent 50%,#fff 0) top/100% 200%,
/* a radial gradient to show only a part of the gradient (20px here)*/
radial-gradient(farthest-side at bottom,#fff calc(100% - var(--b) - 1px),transparent calc(100% - var(--b))),
/* the main gradient */
linear-gradient(to right, green , yellow , red);
}
.box::before {
content:"";
display:block;
padding-top:50%;
}
<div class="box"></div>
<div class="box" style="--b:30px;--p:90deg"></div>
<div class="box" style="--b:10px;--p:40deg"></div>
Another syntax:
.box {
--p:160deg;
--b:20px;
width:250px;
display:inline-block;
border-radius:500px 500px 0 0;
padding:var(--b) var(--b) 0;
background:
linear-gradient(var(--p),transparent 50%,#fff 0) top/100% 200%,
linear-gradient(#fff,#fff) content-box,
linear-gradient(to right, green , yellow , red);
}
.box::before {
content:"";
display:block;
padding-top:50%;
}
<div class="box"></div>
<div class="box" style="--b:30px;--p:90deg"></div>
<div class="box" style="--b:10px;--p:40deg"></div>
And using mask to have transparency:
.box {
--p:160deg;
--b:20px;
width:250px;
display:inline-block;
border-radius:500px 500px 0 0;
background: linear-gradient(to right, green , yellow , red);
-webkit-mask:
radial-gradient(farthest-side at bottom,transparent calc(100% - var(--b) - 1px),#fff calc(100% - var(--b))),
linear-gradient(var(--p),#fff 50%,transparent 0) top/100% 200%;
-webkit-mask-composite:destination-in;
mask-composite:intersect;
}
.box::before {
content:"";
display:block;
padding-top:50%;
}
body {
background:#f3f3f3;
}
<div class="box"></div>
<div class="box" style="--b:30px;--p:90deg"></div>
<div class="box" style="--b:10px;--p:40deg"></div>
I'm trying to put an triangle/arrow under the v-container with some gradient colour but I don't know how to "merge" the gradient.
If I create the arrow with CSS the gradient won't match.
Any ideas about how to achieve this?
Here is the code:
HTML:
<div id="app">
<v-container fluid pa-0 class="gradient white--text">
<v-layout row wrap text-xs-center>
<v-flex xs12>
<h1 class="display-1 my-5">Lorem Ipsum</h1>
</v-flex>
</v-layout>
</v-container>
<div class="bottom-arrow"></div>
</div>
CSS:
.gradient{
height: 300px;
background: rgb(0,105,173);
background: linear-gradient(45deg, rgba(0,105,173,1) 0%, rgba(34,84,132,1) 100%);
}
.bottom-arrow:after {
content:'';
position: absolute;
left: 0;
right: 0;
margin: 0 auto;
width: 0;
height: 0;
border-top: 50px solid rgb(0,105,173);
border-left: 50px solid transparent;
border-right: 50px solid transparent;
}
You can use css clip-path, but the browser support is not that great.
.gradient{
height: 300px;
background: rgb(0,105,173);
background: linear-gradient(45deg, rgba(0,105,173,1) 0%, rgba(34,84,132,1) 100%);
display: flex;
justify-content: space-around;
align-items: center;
/* Clip-path */
/* clip-path: polygon(0% 0%, 100% 0%, 100% calc(100% - 30px), 60% calc(100% - 30px), 50% 100%, 40% calc(100% - 30px), 0% calc(100% - 30px));
padding-bottom: 30px; */
/* Fixed-width arrow */
clip-path: polygon(0% 0%, 100% 0%, 100% calc(100% - 30px), calc(50% + 40px) calc(100% - 30px), 50% 100%, calc(50% - 40px) calc(100% - 30px), 0% calc(100% - 30px));
}
<div id="app" class="gradient">
<h1 class="display-1 my-5">Lorem Ipsum</h1>
</div>
Here is another idea more supported than clip-path but without transparency.
.gradient{
height: 250px;
background:
/* 28.3px = cos(45deg) x 40px
225deg = 180deg + 45deg
*/
linear-gradient( 225deg, transparent 28.3px,#fff 29px) bottom left /50% 40px,
linear-gradient(-225deg, transparent 28.3px,#fff 29px) bottom right/50% 40px,
/*Your gradient*/
linear-gradient(to bottom right, red,yellow ,blue);
background-repeat:no-repeat;
}
<div id="app" class="gradient">
</div>