CSS Gradient border with :after - css

css question.
Is it possible to add a gradient to a border that reflects to the div above?
I can add a solid color, cannot seem to find something for a gradient.
current status
.offerBox {
width: 360px;
height: 170px;
position: relative;
border-radius: 5px;
background: linear-gradient(to right, #fcd651 0%,#f9c100 100%);
}
.offerBox:after {
top: 100%;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-color: rgba(136, 183, 213, 0);
border-top-color: #f9c100;
border-width: 30px;
margin-left: -30px;
}
<div class="offerBox"></div>
Thanks!

You can remove border and apply gradient to :after background
use transform: rotate(45deg); to give it the triangle look.
and z-index: -1; will push it below the offer div.
.offerBox:after {
top: calc(100% - 15px);
left: 50%;
content: " ";
height: 30px;
width: 30px;
position: absolute;
pointer-events: none;
background: linear-gradient(to right, #fcd651 0%, #f9c100 100%);
margin-left: -30px;
transform: rotate(45deg);
z-index: -1;
}
SNIPPET
.offerBox {
width: 360px;
height: 170px;
position: relative;
border-radius: 5px;
background: linear-gradient(to right, #fcd651 0%, #f9c100 100%);
}
.offerBox:after {
top: calc(100% - 15px);
left: 50%;
content: " ";
height: 30px;
width: 30px;
position: absolute;
pointer-events: none;
background: linear-gradient(to right, #fcd651 0%, #f9c100 100%);
margin-left: -30px;
transform: rotate(45deg);
z-index: -1;
}
<div class="offerBox"></div>

You can use as a background, you can change color of gradient as you need. if you need align center bottom you can usetransform:rotate(45deg) translate(-50%, 0); in .offerBox:afterand update top as you need
.offerBox {
width: 360px;
height: 170px;
position: relative;
border-radius: 5px;
background: linear-gradient(to right, #fcd651 0%, #f9c100 100%);
}
.offerBox:after {
top: 95%;
left: 50%;
content: " ";
display: block;
height: 30px;
width: 30px;
background: linear-gradient(to right, tomato 50%, green 100%);
position: absolute;
pointer-events: none;
z-index: -1;
transform: rotate(45deg) translate(-50%, 0);
}
<div class="offerBox"></div>

A possible way to solve your problem : using :before and :after to draw a "box footer" using skew to make a triangle, so that you have a responsive and accurate background gradient.
.offerBox {
position relative;
width: 360px;
height: 170px;
position: relative;
border-radius: 5px;
background: linear-gradient(to right, #fcd651 0%, #f9c100 100%);
}
.offerBox:before {
position: absolute;
bottom: -5px;
left: -10px;
content: " ";
height: 30px;
width: 50%;
pointer-events: none;
background: white;
transform: skew(45deg);
}
.offerBox:after {
position: absolute;
bottom: -5px;
right: -10px;
content: " ";
height: 30px;
width: 50%;
pointer-events: none;
background: white;
transform: skew(-45deg);
}
<div class="offerBox"></div>

Related

How to create css shape for calendar (see image) [duplicate]

This question already has answers here:
CSS Cut out circle from a rectangular shape
(3 answers)
Closed 1 year ago.
Can anyone help me with how to get the style like in the image attached below using background colour for a div? I tried adding using pseudo-classes before and after but doesn't seem to be coming through.
.card {
height: 190px;
background: #070B32;
width: 360px;
position: relative;
}
.card:before {
background: #070B32;
position: absolute;
content: "";
left: 0;
height: 50px;
border-radius: 50% 50% 0 0;
}
.card:after {
background: #070B32;
position: absolute;
content: "";
right: 0;
height: 50px;
border-radius: 50% 50% 0 0;
}
<div class="card">
</div>
Use width top values too to have semi-circles with a change in color
.card {
height: 190px;
background: #070B32;
width: 360px;
position: relative;
}
.card:before {
background: white;
position: absolute;
content: "";
left: 0;
top:35%;
width: 25px;
height: 50px;
border-radius: 0 150px 150px 0;
}
.card:after {
background: white;
position: absolute;
content: "";
right: 0;
top:35%;
width: 25px;
height: 50px;
border-radius: 150px 0 0 150px;
}
<div class="card">
</div>
Update:
div {
height: 150px;
margin: 5em 2em;
background: radial-gradient(circle at left center, transparent, transparent 30px, #070B32 30px, transparent), radial-gradient(circle at right center, transparent, transparent 30px, #070B32 30px, transparent);
border-radius: 8px;
position: relative;
width: 360px;
margin: auto;
}
body {
background-image: url(http://www.fillmurray.com/1000/1000);
background-size: cover;
}
<div>
</div>
you should use width: 50px, background-color: white;
and responsive vertical alignment:
top: 50%; transform: translateY(-50%);
.card {
height: 190px;
background: #070B32;
width: 360px;
position: relative;
}
.card:before {
background: #ffffff;
position: absolute;
content: "";
left: -25px;
top: 50%;
transform: translateY(-50%);
height: 50px;
width: 50px;
border-radius: 50%;
}
.card:after {
background: #ffffff;
position: absolute;
content: "";
right: -25px;
top: 50%;
transform: translateY(-50%);
height: 50px;
width: 50px;
border-radius: 50%;
}
<div class="card">
</div>
Or just use a background.
.card {
--circle-color: #fff;
--circle-size: 50px;
background: radial-gradient(farthest-side circle, var(--circle-color) 97%, transparent) calc(100% + (var(--circle-size) / 2)) 50% / var(--circle-size) var(--circle-size),
radial-gradient(farthest-side circle, var(--circle-color) 97%, transparent) calc(var(--circle-size) / -2) 50% / var(--circle-size) var(--circle-size),
#070B32;
background-repeat: no-repeat;
height: 190px;
width: 360px;
}
<div class="card">
</div>

gradient background doesn't cover under border image

I want background gradient to cover under border image as well. but sounds like It doesn't work at all!
I have realized if I remove Border, It starts working in Mozilla but I want it to work in Google Chrome.
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.cont {
height: 200px;
position: relative;
background-image: linear-gradient(
45deg,
#f09433 0%,
#e6683c 25%,
#dc2743 50%,
#cc2366 75%,
#bc1888 100%
);
background-clip: border-box;
background-repeat: no-repeat;
border: 20px solid orange;
border-image-source: url("https://interactive-examples.mdn.mozilla.net/media/examples/border-diamonds.png");
border-image-slice: 25;
border-image-repeat: round;
border-image-width: 18px;
}
.cont > .insta {
text-align: center;
color: white;
font-size: var(--default-font-size);
margin: 0;
padding: 0;
position: absolute;
width: 80%;
top: 50%;
right: 50%;
transform: translate(50%, -50%);
}
<div class="cont">
<p class="insta">
Follow us on Instagram
</p> </div>
You could put the linear gradient as background to the before pseudo element, making that bigger than the actual element by the width of the border and positioning it respectively. It will then go under the border image of the main element.
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.cont {
height: 200px;
position: relative;
background-clip: border-box;
background-repeat: no-repeat;
border: 20px solid orange;
border-image-source: url("https://interactive-examples.mdn.mozilla.net/media/examples/border-diamonds.png");
border-image-slice: 25;
border-image-repeat: round;
border-image-width: 18px;
position: relative;
}
.cont::before {
content: '';
position: absolute;
width: calc(100% + 40px);
height: calc(100% + 40px);
top: -20px;
left: -20px;
z-index: -1;
background-image: linear-gradient( 45deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
}
.cont>.insta {
text-align: center;
color: white;
font-size: var(--default-font-size);
margin: 0;
padding: 0;
position: absolute;
width: 80%;
top: 50%;
right: 50%;
transform: translate(50%, -50%);
}
<div class="cont">
<p class="insta">
Follow us on Instagram
</p>
</div>

Z-index of the pseudo-element of the parent element, of the child element and the child itself [duplicate]

This question already has answers here:
Why can't an element with a z-index value cover its child?
(5 answers)
Closed 2 years ago.
How to make the z-index of the pseudo-element of the parent element higher than z-index of the pseudo-element of the child element, but the child itself has the highest z-index?
I want the red stripe to cover the gray rectangle but not cover the title itself.
Here is a fiddle
.wrapper {
position: relative;
background: #000;
overflow: hidden;
}
.wrapper::after {
content: "";
position: absolute;
width: 650px;
height: 1500px;
background: rgb(244,116,31);
background: -moz-linear-gradient(top, rgba(244,116,31,1) 0%, rgba(218,14,6,1) 100%);
background: -webkit-linear-gradient(top, rgba(244,116,31,1) 0%,rgba(218,14,6,1) 100%);
background: linear-gradient(to bottom, rgba(244,116,31,1) 0%,rgba(218,14,6,1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f4741f', endColorstr='#da0e06',GradientType=0 );
transform: rotate(40deg);
opacity: .6;
right: 100px;
top: -200px;
z-index: 10;
}
.text-block {
position: relative;
z-index: 10;
width: 70%;
margin: 0 auto;
padding: 50px;
}
.text-block::after {
content: "";
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: #2b2525;
z-index: -1;
}
h1 {
position: relative;
color: #fff;
z-index: 12;
}
<div class="wrapper">
<div class="text-block">
<h1>Text with the biggest z-index and not covered by red stripe</h1>
</div>
</div>
I removed the z-index everywhere and added it to the h1 like this:
.wrapper {
position: relative;
background: #000;
overflow: hidden;
}
.wrapper::after {
content: "";
position: absolute;
width: 650px;
height: 1500px;
background: rgb(244,116,31);
background: -moz-linear-gradient(top, rgba(244,116,31,1) 0%, rgba(218,14,6,1) 100%);
background: -webkit-linear-gradient(top, rgba(244,116,31,1) 0%,rgba(218,14,6,1) 100%);
background: linear-gradient(to bottom, rgba(244,116,31,1) 0%,rgba(218,14,6,1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f4741f', endColorstr='#da0e06',GradientType=0 );
transform: rotate(40deg);
opacity: .6;
right: 100px;
top: -200px;
}
.text-block {
position: relative;
width: 70%;
margin: 0 auto;
padding: 50px;
}
.text-block::after {
content: "";
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: #2b2525;
}
h1 {
position: relative;
color: #fff;
z-index: 1;
}
fiddle

Hollow inverted pentagon

I am trying to make a hollow ( transparent on the inside ) inverted pentagon like this:
Inverted Pentagon
I have attempted to do this using the following css:
.pentagon {
border: solid 86px #E44126;
border-bottom: none;
width: 100%;
height: 60%;
position: absolute;
}
.pentagon:before {
content: "";
position: absolute;
top: 100%;
right: 0px;
width: 50%;
height: 100px;
background: -webkit-linear-gradient(to right bottom, transparent 50%, #E44126 50%,);
background: linear-gradient(to right bottom, transparent 50%, #E44126 50%);
}
.pentagon:after {
content: "";
position: absolute;
top: 100%;
left: 0px;
width: 50%;
height: 100px;
background: -webkit-linear-gradient(to right bottom, transparent 50%, #E44126 50%);
background: linear-gradient(to left bottom, transparent 50%, #E44126 50%);
}
But I just can figure it out. I thought about using clip-path but there is no browser support for IE.
Here is a go at it but using a rotation instead. Values can be tweaked for width/height/border size. http://codepen.io/anon/pen/KWqEqL
* {
box-sizing: border-box;
}
.container {
width: 100px;
height: 100px;
position: relative;
}
.pentagon {
border: solid 5px #E44126;
border-bottom: none;
width: 100%;
height: 50%;
}
.pentagon:before {
content: '';
display: inline-block;
width: 65%;
height: 65%;
border: 5px solid #E44126;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
transform: rotate(45deg);
border-top: 0;
border-left: 0;
}
HTML:
<div class="container"><div class="pentagon"></div></div>

Change color of stripes

I have a striped black diamond using the class diamond (see fiddle here):
.diamond {
border: 8px solid black;
overflow: hidden;
position: relative;
margin: 0 auto;
padding: 12%;
width: 0;
-webkit-transform: scaleY(0.5) rotate(45deg);
}
.diamond:before {
position: absolute;
top: 0;
right: -37.5%;
bottom: 0;
left: -37.5%;
background: -webkit-linear-gradient(black 50%, transparent 50%);
-webkit-transform: scaleY(1.155) skewX(-30deg) rotate(30deg);
background-size: 10px;
content: '';
}
Now I want a class red that will make the diamond red, both the border and the stripes. I have managed to impose a red border, but not the red stripes. How can I modify the CSS for .red such that the stripes become red?
.diamond {
border: 8px solid black;
overflow: hidden;
position: relative;
margin: 0 auto;
padding: 12%;
width: 0;
-webkit-transform: scaleY(0.5) rotate(45deg);
}
.diamond:before {
position: absolute;
top: 0;
right: -37.5%;
bottom: 0;
left: -37.5%;
background: -webkit-linear-gradient(black 50%, transparent 50%);
-webkit-transform: scaleY(1.155) skewX(-30deg) rotate(30deg);
background-size: 10px;
content: '';
}
.red {
border-color: crimson !important;
}
.red:before {
background-image: -webkit-linear-gradient(red 50%, transparent 50%);
}
Fiddle http://jsfiddle.net/UQQMz/1/
Your problem is the order of precedence. The red class is handled before the diamond class because it appears in the CSS first. Move the red classes below the diamond class to fix your problem.

Resources