Slantic shadow of circle in CSS [duplicate] - html

So I know how to do a basic box shadow with CSS3. You can see that in the top of the graphic below.
The effect I'm trying to achieve is a 3D box shadow, as shown in the bottom of the graphic below.
Any ideas on how to do this with CSS3 box shadows?

Unfortunately box shadows are effectively just flat layers. However you can apply multiple box shadows to create this effect.
.box-shadow-3d{
box-shadow: 1px 1px 0px #999,
2px 2px 0px #999,
3px 3px 0px #999,
4px 4px 0px #999,
5px 5px 0px #999,
6px 6px 0px #999;
}

you can use pseudo element for as shadow
div {
background: black;
height: 100px;
width: 100px;
position: relative;
}
div:after,
div:before {
content: '';
background: grey;
position: absolute;
}
div:after {
width: 100%;
height: 20px;
left: 10px;
bottom: 0;
transform: translatey(100%) skewx(45deg);
}
div:before {
width: 20px;
height: 100%;
right: 0;
transform: translatex(100%) skewy(45deg);
top: 10px;
}
<div></div>

Here is a real 3D shadow using perspective and pseudo-element :before.
body {
background: lightblue;
}
.foo {
position: relative;
display: inline-block;
-webkit-perspective: 1000px;
-moz-perspective: 1000px;
persepctive: 1000px;
margin: 20px;
margin-top: 50px;
}
.foo .box {
transform: rotateY(-40deg);
height: 350px;
width: 250px;
background-color: black;
}
.foo:before {
content: "";
top: -15px;
position: absolute;
width: 50px;
height: 375px;
background-color: grey;
transform: translateX(215px) translateY(2.7px) rotateY(55deg)
}
<div class="foo">
<div class="box"></div>
</div>

You can stack the horizontal/vertical offsets of several box-shadows, each slightly bigger than the previous one. The more shadows you add, the more pronounced the effect. Here is a fiddle example.
div {
background: black;
height: 100px;
width: 100px;
box-shadow: 0 01px gray,
01px 0 gray,
01px 02px gray,
02px 01px gray,
02px 03px gray,
03px 02px gray,
03px 04px gray,
04px 03px gray,
04px 05px gray,
05px 04px gray,
05px 06px gray,
06px 05px gray;
}

I had some problems with these two options, so I adapted some diagonal gradients from Lea Verou's excellent book CSS Secrets. I thought about creating a gradient inside a right and bottom border via border-image, but that property does not allow edge targeting, à la border-right-image, etc.
So, I settled on using a pseudo element with two truncated corners, which seems to work pretty well. You have to be careful to adjust the width of the gradient to be 1.414 the size of half the padding, since this would be the diagonal of a square (square root of two). Also, since that's a pseudo element, be careful of the right placement. Interested to hear what you folks think.
div {
background: #bbb;
padding: 1em 1.2em;
width: 50%;
margin: 0 auto;
color: #111;
font: 150%/1.2 Georgia, Palatino, Times, serif;
position: relative;
}
div:after {
content:" ";
position:absolute;
top:0;
left: 0;
width:100%;
height:100%;
padding: 1.42em; /* (square root of gradient position) */
background: #000; /* Fallback if not supported */
background: linear-gradient(-135deg, transparent 2em, #000 0) top right,
linear-gradient(#000, #000) padding-box bottom right,
linear-gradient(45deg, transparent 2em, #000 0) bottom left;
/*I have avoided adding -webkit-, -moz and -0 prefixs for linear-gradient. You may put them in later to be extra safe*/
background-size: 50% 50%; /* There is no reason to paint the upper left quadrant, so I didn't. */
background-repeat: no-repeat;
-webkit-box-sizing: content-box; -moz-box-sizing: content-box; box-sizing: content-box;
/* Many people use border-box as default these days. Unfortunately, the box cannot be sized using border-box settings with the combination of padding in ems and percentages. So this is reset to content-box, just in case. */
z-index: -1; /* To keep the shadow behind the div*/
<div>This is a short sentence to demonstrate that our little div is responsive.</div>

Here's a little implementation, inspired by #Vitorino fernandes, in stylus...
offset = 10
border = 3
.offsetbox
margin offset
padding offset
text-align center
box-shadow inset 0 0 0 unit(border,px) black
background white
display inline-block
position relative
&:after,
&:before
content ''
background black
position absolute
&:after
width 100%
height offset
transform translatey(100%) skewx(-45deg)
right (offset/2)
bottom 0
&:before
height 100%
width offset
transform: translatex(-100%) skewy(-45deg)
left 0
top (offset/2)

I added some clip paths to #Vittorino fernandes code, to avoid white space between pseudos and make it sharper.
I added some 1px adjustments to avoid bad svg rendering problems.
You can use the variable called shadow-dimension to set the shadow width and height.
I Put it on a codePen:
https://codepen.io/silviamalavasi/pen/XWqeWEq
:root {
--shadow-dimension: 20px;
--blue: #0039a6;
}
.box-container {
position: relative;
}
.box-container>div {
border: 2px solid var(--blue);
}
.box-container>div:after, .box-container>div:before {
content: '';
background-color: var(--blue);
position: absolute;
}
.box-container>div:before {
width: calc(var(--shadow-dimension) + 1px);
height: calc(100% + 100px + 1px);
left: calc(var(--shadow-dimension) * -1);
transform: skewy(-45deg);
top: calc(0.5*var(--shadow-dimension));
clip-path: polygon(0% 0%, 100% 0%, 100% calc(100% - 100px - 2px + var(--shadow-dimension)), 0% calc(100% - 100px - 2px));
}
.box-container>div:after {
width: calc(100% + 100px);
height: calc(var(--shadow-dimension) + 1px);
left: calc(-0.5*var(--shadow-dimension) - 100px);
bottom: 1px;
transform: translateY(100%) skewx(-45deg);
clip-path: polygon(100px 0%, 100% 0%, 100% 100%, calc(100px + 2px) 100%);
}

Related

How to scale a triangle with rectangle content in css?

I have created a triangle with a border and a coloured background. However it is attached to a rectangle with some content and i can't figure out how to scale the triangle with it.
I have used a pseudo element and put a triangle on top of another triangle to create the border, so not sure if this way is possible to scale with.
My problem is the triangle
HTML:
<div class="skipcontent">
<i class="bi bi-skip-end-circle" style="font-size:36px;"></i>
<p class="alertcontent">content can span onto 2 lines. content can span onto 2 lines. content can span onto 2 lines. content can span onto 2 lines. </p>
</div>
</div>
Here is my CSS:
.container {
width: 700px;
height: 100%;
background: #D9F1FF;
border: 1px solid #7197C9;
position: relative;
color: #000000;
font-size:15px;
border-radius: 5px;
font-family: Arial,Helvetica,sans-serif;
}
/* this CS forms the triangles */
.container:after,
.container:before {
content: '';
display: block;
position: absolute;
left: 100%;
width: 0;
height: 0;
border-style: solid;
}
/* this border color controls the color of the triangle (what looks like the fill of the triangle) */
.container:after {
top: 0px;
border-color: transparent transparent transparent #D9F1FF;
border-width: 26px;
margin-left:-2px;
}
/* this border color controlls the outside, thin border */
.container:before {
top: 0px;
border-color: transparent transparent transparent #7197C9;
border-width: 26px;
margin-left:-1px;
}
.skipcontent {
padding:0 0 0 20px;
display:flex;
align-items:center;
}
You can do it easily by using "Clippy - clip-path". But you can't add the border and border-radius on everywhere.
Reference site link - https://bennettfeely.com/clippy/
Demo Screenshot - https://prnt.sc/-J3_o3rHqlFU
.skipcontent {
color: #ffffff;
background: red;
border-radius: 5px;
padding: 20px 40px;
clip-path: polygon(50% 0%, 97% 0, 100% 28%, 97% 50%, 97% 100%, 0 100%, 0% 35%, 0 0);
}

CSS transform scale ignor z-index and gradient

I use linear-gradient on ::after to make a object like this, a disappeared border. now I want to use scale to make one of them such active (selected) but look like it ignore z-index: -1; and show all gradient. I want to display selected one like others.
.Winter-Plans {
width: calc(100%/5 - 16px);
min-height: 360px;
position: relative;
border-radius: 20px;
background: white;
padding: 80px 15px 35px 15px;
margin: 0 8px 20px 8px;
box-sizing: border-box;
float: left;
}
.Winter-Plans::after {
position: absolute;
top: -1px;
bottom: -1px;
left: -1px;
right: -1px;
background: linear-gradient(to top, #ddd, white);
content: '';
z-index: -1;
border-radius: 20px;
}
.Winter-Plans.Selected {
transform: scale(1.1);
}
<div class="Winter-Plans">
</div>
<div class="Winter-Plans Selected">
</div>
<div class="Winter-Plans">
</div>
There are lot of topics by this title, I tried but none of them solved my isssue. ps: I can't change html structure, for this reason I used ::after
transform will create a stacking context forcing the pseudo element to be painted inside an no more outside/behind your element. Related question to better understand the issue: Why can't an element with a z-index value cover its child?
Consider a different way to do the same effect by using multiple background where you don't need pseudo element
.Winter-Plans {
width: calc(100%/5 - 16px);
min-height: 360px;
border-radius: 20px;
background:
linear-gradient(white,white) padding-box, /* cover only the padding area*/
linear-gradient(to top, #ddd, white) border-box; /* cover the border area*/
border:1px solid transparent; /* a transparent border for our gradient */
padding: 80px 15px 35px 15px;
margin: 0 8px 20px 8px;
box-sizing: border-box;
float: left;
}
.Winter-Plans.Selected {
transform: scale(1.1);
}
<div class="Winter-Plans">
</div>
<div class="Winter-Plans Selected">
</div>
<div class="Winter-Plans">
</div>
In case you need a solution with a transparent background and a border gradient with radius check this: Border Gradient with Border Radius

Angled CSS background with bottom border.

I'm trying to create a CSS background that looks like this:
I've been able to create the shape, but can't figure out how to add the bottom border, and am starting to think my approach may be the problem.
So far I have the following CSS:
#top-background-flag {
border-top: 2px solid #C2C2C2;
background: linear-gradient(
to bottom right,
#5DCAD3 50%,
transparent 50.5%
)
no-repeat bottom, /* bottom part */
linear-gradient(100deg, #5DCAD3, #5DCAD3) no-repeat top;
/* top portion */
padding-bottom: 3.5rem;
border-bottom: 2px solid #C2C2C2;
background-size: 100% 3rem, 100% calc(100% - 3rem)
}
and HTML:
<div id=top-background-flag>
A fun title
</div>
and a code pen: https://codepen.io/arel/pen/PKXGmd
My problem right now is that the bottom border is a horizontal line, and I can't figure out how to have it follow the angle of the box.
Here is what I have so far:
Trying to use a linear gradient may not be the best solution here.
Appending an object with a little CSS transformation some judicious layering will accomplish what you want and will have fewer properties to adjust if you want to change the angle later.
#top-background-flag {
border-top: 2px solid #C2C2C2; /* top border on the parent */
position: relative;
padding-bottom: 3.5rem;
overflow: hidden;
}
#top-background-flag:before {
background-color: #5DCAD3;
transform: skewy(-4deg); /* angle you want */
transform-origin: bottom left;
border-bottom: 2px solid #C2C2C2; /* bottom border skews with the object */
content: ' ';
display: block;
height: 100%;
width: 100%;
position: absolute;
z-index: -1;
bottom: 0;
}
Here is a working example to play with
Add this CSS to fake a bottom border:
#top-background-flag:after {
content: "";
background-color: red;
height: 2px;
width: 100%;
position: absolute;
left: 0;
bottom: 23px;
transform: rotate(-5.5deg);
}
Here is a working fork of your codepen: https://codepen.io/anon/pen/XaojPp
I'm not sure that this is what you are looking for, but you can use the :after pseudo class with the content trick:
body {
max-width: 500px;
}
#top-background-flag {
border-top: 2px solid #C2C2C2;
background: linear-gradient(
to bottom right,
#5DCAD3 50%,
transparent 50.5%
)
no-repeat bottom, /* bottom part */
linear-gradient(100deg, #5DCAD3, #5DCAD3) no-repeat top;
/* top portion */
padding-bottom: 3.5rem;
border-bottom: 2px solid #C2C2C2;
background-size: 100% 3rem, 100% calc(100% - 3rem);
position: relative;
}
#top-background-flag:after {
content: '';
border-bottom: 1px solid red;
border-top: 1px solid red;
position: absolute;
width: 100%;
bottom: 22px;
left: 0;
transform: rotate(-5.5deg);
}
<div id=top-background-flag>
A fun title
</div>

Adding corners to a eye shaped element

I have this eye shaped element here
body {
background: grey;
}
.eye-focus {
box-sizing: content-box;
width: 75%;
padding: 30% 0 0 0;
margin: 0 auto;
border-radius: 50%;
background-image: radial-gradient(circle, #000 8%, #a50 8%, #0b0 18%, #080 35%, #fff 35%);
position: relative;
}
.eye-left {
position: absolute;
left: -4%; top: 32%;
border-right: 2em solid white;
border-bottom: 2em solid transparent;
border-top: 2em solid transparent;
}
.eye-right {
position: absolute;
right: -4%; top: 32%;
border-left: 2em solid white;
border-bottom: 2em solid transparent;
border-top: 2em solid transparent;
}
<div class="paragraph">
<div class="eye-focus">
<div class="eye-left"></div>
<div class="eye-right"></div>
</div>
my paragraph text
</div>
jsfiddle if you'd prefer: https://jsfiddle.net/wneupyr4/
I've tried many things and none gave me the result I wanted.
I started reading into pseudo elements, but those are pretty new to me. so I couldn't do much, if some at all.
The basic concept is that those edges will make the whole eye look even more like a real one, if they will stay centered.
If you rotate the div 45deg, you can easily get the sharp edges on the sides.
First make it a square, by putting the width and padding-top(or bottom) be the same value.
Then use transform: rotate(45deg) to rotate it. And finally border-radius of 100% to top and bottom borders to retain the eye shape.
Additionally you can use a negative margin to "cut" some of the size we get when rotating (there is a bigger distance diagonally).
body {
background: grey;
}
.eye-focus {
box-sizing: content-box;
width: 55%;
padding-top: 55%;
margin: -10% auto; /* negative margin to account for the rotation */
border-radius: 100% 0;
background-image: radial-gradient(circle, #000 8%, #a50 8%, #0b0 18%, #080 35%, #fff 35%);
transform: rotate(45deg);
}
<div class="paragraph">
<div class="eye-focus"></div>
<div class="ptext">my paragraph text</div>
</div>
jsfiddle
To make an eye or a "pointy ellipse" or "football" or "stewie head", you can just use border-radius on 2 opposite corners, leave the other corners alone, then rotate the eye.
.eye {
width: 10vw;
height: 10vw;
background: #000;
border-radius: 0 50%;
transform: rotate(-45deg);
transform-origin: 100% 0; /* to position/keep the elemen on the page after rotation. use this as you see fit */
}
<div class="eye"></div>

Right banner arrows purely in CSS

I'm trying to recreate these arrows in CSS for a website I'm redesigning to be responsive. These two guys were done with static images but I'd like them to be pure CSS.
This is a sprite that was used for mouseover replacement. The bottom is the mouseover state. The background behind the arrow needs to be transparent.
I thought it would be a simple div with a p or heading tag inside:
<div class="arrow_box">
<p>UTILITIES</p>
</div>
I've searched for examples everywhere and everything I've tried to modify never lets me seem to have full control of the width and height of the element. The width (with the arrow) is 114px. The height (of a single state) would be 29px.
I've played with this for the better part of an hour trying to get it properly sized but nothing seems to work. http://codepen.io/anon/pen/bpBGQL My lack of knowledge on how this works is partially to blame.
So the trick, here, is being able to control the height correctly. Here, I've got the text in a span with a line-height : 0, and padding:15px. Now, we have precisely 30px of height, and can use an ::after pseudo element to fabricate the arrow. The width will be set by the text content, but can be defined with an explicit width rule, as well.
<div class="arrow"><span>text</span></div>
.arrow{
display:inline-block;
height:auto;
background-color:orange;
}
.arrow span{
display:inline-block;
line-height:0;
padding:15px;
color:white;
}
.arrow::after{
width: 0;
height: 0;
position: absolute;
right:0
top: 0;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-left: 15px solid orange;
content: "";
}
Add whatever colors / hover states you require. You can see some basic rules in the working fiddle.
Fiddle
You can do this with :after pseudo element. You can change color of pseudo element on hover state like this .arrow_box:hover:after
* {
box-sizing: border-box;
}
p {
margin: 0;
padding-left: 10px;
}
.arrow_box {
background: #627680;
display: block;
color: white;
position: relative;
height: 30px;
line-height: 30px;
width: 114px;
transition: all 0.3s ease-in;
}
.arrow_box:after {
content: '';
height: 0;
width: 0;
position: absolute;
top: 0;
right:0;
transform: translateX(100%);
border-bottom: 15px solid transparent;
border-top: 15px solid transparent;
border-left: 20px solid #627680;
border-right: 15px solid transparent;
transition: all 0.3s ease-in;
}
.arrow_box:hover {
background: #2A92C2;
}
.arrow_box:hover:after {
border-left: 20px solid #2A92C2;
}
<div class="arrow_box">
<p>UTILITIES</p>
</div>
did you consider gradient backgrounds ?
body {
background: linear-gradient(45deg, gray, lightgray, gray, lightgray, gray, lightgray, gray, lightgray, gray, lightgray, gray, lightgray);
/* demo purpose only */
}
.arrow {
text-transform: uppercase;
/* optionnal */
padding: 3px 1.5em 3px 0.5em;
color: white;
background: linear-gradient(225deg, transparent 0.6em, #627680 0.6em) top no-repeat, linear-gradient(-45deg, transparent 0.6em, #627680 0.6em) bottom no-repeat;
background-size: 100% 50%;
/* each gradient draws half of the arrow */
}
.arrow:hover {
/* update gradient color */
background: linear-gradient(225deg, transparent 0.6em, #2A92C2 0.6em) top no-repeat, linear-gradient(-45deg, transparent 0.6em, #2A92C2 0.6em) bottom no-repeat;
background-size: 100% 50%;
}
<span class="arrow"> Utilities</span> <span class="arrow"> testing</span>
You may also want to take a look at Responsive Arrow Breadcrumb Navigation for breadcrumbs and imbricated arrows or Create dynamic arrow-like shape with CSS
Does this pen provide what you need?
http://codepen.io/anon/pen/dMOPmV (may require some pixel pushing to get it perfect)
It just required adjusting:
border-width: 27px;
margin-top: -35px;
and adding a hover state for the main element and before element.