3D-like hover effect on button - css

I'm trying to replicate this effect with pure CSS:
So far I've tried doing:
.parent {
height: 90vh;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.hoverable-element {
border: 0.1rem solid #000;
background: #fff;
padding: 1rem 2rem;
transform: translate(0, 0);
box-shadow: 0 0 0 #000;
transition:
box-shadow 200ms ease-out,
transform 200ms ease-out;
}
.hoverable-element:hover {
transform: translate(-0.5rem, -0.5rem);
box-shadow:
0.1rem 0.1rem 0 #000,
0.2rem 0.2rem 0 #000,
0.3rem 0.3rem 0 #000,
0.4rem 0.4rem 0 #000,
0.5rem 0.5rem 0 #000;
}
<div class="parent">
<button class="hoverable-element">Hoverable Button</button>
</div>
But this method repeats a lot of unnecessary code, as well as not properly doing what I intended.
I want the button "shadow" or hover-effect-thingy to be bordered with a white background (as shown in the image). Other than that I'm clueless as to where to start

here is an idea with pseudo element and skew transformation:
.parent {
height: 90vh;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.hoverable-element {
border: 1px solid #000;
background: #fff;
padding: 1rem 2rem;
position: relative;
transition: transform 0.5s;
}
.hoverable-element::before,
.hoverable-element::after {
content: "";
position: absolute;
border: inherit;
transition: inherit;
}
.hoverable-element::before {
height: 1rem;
top: 100%;
left: -1px;
right: -1px;
transform-origin: top left;
transform: skewX(45deg) scaleY(var(--s, 0));
}
.hoverable-element::after {
width: 1rem;
left: 100%;
top: -1px;
bottom: 0;
border-bottom:none;
transform-origin: bottom left;
transform: skewY(45deg) scaleX(var(--s, 0));
}
.hoverable-element:hover {
transform: translate(-0.5rem, -0.5rem);
--s: 1;
}
<div class="parent">
<button class="hoverable-element">Hoverable Button</button>
</div>

Related

z index multiple elements

hey guys I have 3 elements I'm using z-index and position property.
the first one is the main navbar (working fine)
the 2nd is sidenav
the 3rd is a button.
the button must have the position relative.
when I'm scrolling the main navbar is taking over the button which is great !
but the side navbar is not.
I did try to change the z-index on each element.
the mobile navbar is the main navbar which working fine.
.mobile-navbar {
background-color: rgb(0, 0, 0);
position: fixed;
z-index: 1;
width: 100%;
display: flex;
justify-content: space-between;
img {
background-color: rgba(0, 0, 0, 0.274);
}
div {
display: flex;
justify-content: center;
align-items: center;
a {
font-size: 2rem;
color: #fff;
margin: 5px;
text-decoration: none;
span {
background-color: red;
border-radius: 10px;
padding: 0 3px;
}
}
}
}
.side-nav {
position: fixed;
z-index: 0;
width: 100%;
height: 100vh;
transform: translateX(-100%);
transition: 300ms ease-out;
&-active {
position: fixed;
width: 100%;
height: 100vh;
background-color: rgb(12, 6, 39);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
transform: translateX(0);
transition: 300ms ease-out;
button.close-nav {
padding: 5px;
background-color: rgb(14, 12, 12);
color: #fff;
border: none;
font-size: 2rem;
font-weight: 700;
}
.dynamic-links {
height: 30%;
button {
padding: 5px;
font-size: 2rem;
background: rgba(0, 0, 0, 0);
color: #fff;
border: none;
}
.sidenav-link {
color: #fff;
text-decoration: none;
font-size: 2rem;
margin: 0 10px;
}
}
.sidenav-links {
display: flex;
flex-direction: column;
height: 50%;
.sidnav-link {
color: #fff;
margin: 10px 0;
font-size: 2rem;
text-decoration: none;
text-align: center;
}
}
}
}
the button I need to use position relative and taking over the side-navbar:
button {
position: relative;
z-index: 0;
cursor: pointer;
font-size: 1.3rem;
padding: 10px 15px;
border: none;
outline: #06a821;
border-radius: 30px;
color: #fff;
letter-spacing: 0.3rem;
background: linear-gradient(
90deg,
rgba(5, 116, 197, 1) 35%,
rgba(106, 183, 239, 1) 100%
);
transition: ease-in-out 300ms;
&::before {
position: absolute;
border: 1px solid #fff;
left: 5px;
right: 5px;
top: 5px;
bottom: 5px;
border-radius: 30px;
content: "";
}
only had to add the z-index in the active class.
befor :
.side-nav {
position: fixed;
z-index: 0;
width: 100%;
height: 100vh;
transform: translateX(-100%);
transition: 300ms ease-out;
&-active {
position: fixed;
width: 100%;
height: 100vh;
background-color: rgb(12, 6, 39);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
transform: translateX(0);
transition: 300ms ease-out
after:
.side-nav {
position: fixed;
width: 100%;
height: 100vh;
transform: translateX(-100%);
transition: 300ms ease-out;
&-active {
position: fixed;
z-index: 1;
width: 100%;
height: 100vh;
background-color: rgb(12, 6, 39);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
transform: translateX(0);
transition: 300ms ease-out;

Box-shadow on div with border-radius 50% visible on Mozilla and not Chrome / Edge

I have a little CSS issue and I have no idea why :
As you can see, Edge and Chrome are "normal" but on Mozilla the shadow is visible and I have no idea why...I checked on canaiuse (https://caniuse.com/#feat=css-boxshadow) and I didn't see compatibility problem, someone have an idea why?
Here is the html / css of this part :
HTML
My Doctype : <!DOCTYPE html>
<div class="myclass col-5">
<i class="fas fa-camera-retro" aria-hidden="true"></i>
<i class="fas fa-images" aria-hidden="true"></i>
<i class="fas fa-cogs" aria-hidden="true"></i>
</div>
CSS - SASS (here is my .scss before I compile)
.myclass {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
align-items: center;
padding-right: 0;
#include position(absolute, 0, 0, null, null);
a.btn {
height: 30px;
width: 30px;
border-radius: 50%;
text-align: center;
padding: 0;
position: relative;
transition: all .2s ease-out;
box-shadow: 0 0 0 0 $grey-dark;
z-index: 50;
&:hover {
transform: translate(2px, -2px);
box-shadow: -2px 2px 0px 0px $grey-dark;
}
.fa-cogs,
.fa-camera-retro,
.fa-images {
color: $white;
}
svg {
display: block;
margin: 0 auto;
#include vertical-align();
}
}
}
I tried to remove the data-balloon part of my link just to see if the balloon.css I the problem but nothing change
PS : if you need the CSS after I compile tell me, but you should see what I do with the code bellow
EDIT : Here is a snippet where you can see the problem if you open it on MOZILLA
div {
flex-flow: row nowrap;
justify-content: space-between;
align-items: center;
padding-right: 0;
}
div a {
display: inline-block;
height: 30px;
width: 30px;
border-radius: 50%;
text-align: center;
padding: 0;
position: relative;
transition: all .2s ease-out;
box-shadow: 0 0 0 0 black;
z-index: 50;
background: orange;
}
div a:hover {
transform: translate(2px, -2px);
box-shadow: -2px 2px 0px 0px black;
}
<div>
<a></a>
<a></a>
<a></a>
</div>
I tested your code and its working fine. I don't see any box-shadow issue here...However if issue is there you can just set box-shadow color to transparent at normal state and change it on :hover
div {
height: 30px;
width: 30px;
border-radius: 50%;
text-align: center;
padding: 0;
position: relative;
transition: all .2s ease-out;
box-shadow: 0 0 0 0 transparent;
z-index: 50;
background: orange;
}
div:hover {
transform: translate(2px, -2px);
box-shadow: -2px 2px 0px 0px grey;
}
<div></div>

How to make an image show over an element's padding region in CSS?

Current Situation Image
Here is what I have got. But I want that rectangle facebook image behind the red region (currently it is just behind the text 'Please')
#mlnk{
text-decoration:none;
position:relative;
top:40%;
left:0%;
color: #b5c5d6;
}
.container-corner-img{ /* **THIS IS TO BE PUSHED BACK** */
height: 40%; width: 70%;
position: absolute;
top: 5px; left:-75px;
}
.container{
width:50%;
height:30%;
background: linear-gradient(#8B9DC1, #3b5998);
padding:100px;
border-radius:12px;
position: relative;
font-family: sans-serif;
}
h1{ /* **THIS NEEDS TO BE BROUGHT TO FRONT** */
margin-left: auto;
margin-right: auto;
padding: 8px;
border-radius: 4px;
box-shadow: 0 4px 6px 0 rgba(0,0,0,0.2);
transition: 0.4s ease;
background-color: red;
margin-top: 0;
}
img{
height: 80%;
width: 50%;
}
<div class="container">
<div class="container-corner-img">
<img src="fbminimal.png">
</div>
<h1>
<a id="mlnk" href = "#link"> Please login to your facebook account first</a>
</h1>
</div>
I have commented the css definitions in CAPS that needs to be focused according to me.
To bring the heading to the front, you have to set z-index to a larger value. To be able to use z-index on an element it needs to have a different position than static. So use relative. Moreover, do not use the center-tag since it is deprecated. The layout should be controlled by CSS only.
#mlnk {
text-decoration: none;
position: relative;
top: 40%;
left: 0%;
color: #b5c5d6;
}
h3 {
color: midnightblue;
padding: 4px;
box-shadow: 0 2px 4px 0 #38434e;
background: #3c64ad;
}
.container-corner-img {
/* **THIS IS TO BE PUSHED BACK** */
height: 40%;
width: 70%;
position: absolute;
top: 5px;
left: -75px;
/* opacity: 0.4; */
}
.container {
width: 50%;
height: 30%;
background: linear-gradient(#8B9DC1, #3b5998);
padding: 100px;
border-radius: 12px;
position: relative;
font-family: sans-serif;
/* z-index: 1; */
margin: 0 auto;
}
h1 {
/* **THIS NEEDS TO BE BROUGHT TO FRONT** */
margin-left: auto;
margin-right: auto;
padding: 8px;
border-radius: 4px;
box-shadow: 0 4px 6px 0 rgba(0, 0, 0, 0.2);
transition: 0.4s ease;
background-color: red;
/* rgba(0,0,80,0.2); */
margin-top: 0;
/* Add this */
position: relative;
z-index: 1000;
}
h1:hover {
box-shadow: 0 4px 6px 0 rgba(0, 0, 0, 0.2), 0 6px 8px 0 rgba(0, 0, 0, 0.19);
transition: 0.4s ease;
}
img {
height: 80%;
width: 50%;
/* z-index: 0; */
}
.center {
text-align: center;
margin: 0 auto;
}
<div class="center">
<div class="container">
<div class="container-corner-img">
<img src="https://stocknews.com/wp-content/uploads/2017/07/facebook-fb-alternate.jpg">
</div>
<h1>
<a id="mlnk" href="#link"> Please login to your facebook account first</a>
</h1>
<h3>You need to Log In</h3>
</div>
</div>

border-radius gradient with transparent background

I have this simple CSS spinner, here:
html {
background: black;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
#keyframes k__common-spin-cw {
0% {
transform: rotate(0);
}
100% {
transform: rotate(360deg);
}
}
.wd-spinner {
height: 30px;
width: 30px;
border-style: solid;
border-color: rgba(255, 255, 255, 0.15);
border-width: 2px;
border-radius: 100%;
border-top-color: #00ba8c;
-webkit-animation: k__common-spin-cw 700ms linear infinite;
animation: k__common-spin-cw 700ms linear infinite;
}
<div class="wd-spinner"></div>
Is it possible to have a gradient border with border-radius, and instead of having the tail of the highlighted border-top just abruptly end, make it a nice gradient fade, while also keeping the background transparent?
I have removed the animation and increased the size to make the effect more easily visible.
With a pseudo, I have added a shadow of the same color than the border to create the fade.
Hover on the div and the overflow hidden will be applied, setting the final effect
html {
background: black;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.wd-spinner {
height: 200px;
width: 200px;
border-radius: 100%;
position: relative;
}
.wd-spinner:hover {
overflow: hidden;
}
.wd-spinner:after {
content: "";
position: absolute;
height: 196px;
width: 196px;
border-style: solid;
border-color: rgba(255, 255, 255, 0.15);
border-width: 2px;
border-radius: 100%;
border-top-color: #00ba8c;
}
.wd-spinner:before {
content: "";
position: absolute;
height: 196px;
width: 196px;
top: 2px;
left: 2px;
border-radius: 100%;
box-shadow: -40px -40px 70px -22px #00ba8c;
}
<div class="wd-spinner"></div>

Add border to triangle element in css3

This is my code
CSS
#page {
width: 900px;
padding: 0px;
margin: 0 auto;
direction: rtl;
position: relative;
}
#box1 {
position: relative;
width: 500px;
border: 1px solid black;
box-shadow: -3px 8px 34px #808080;
border-radius: 20px;
box-shadow: -8px 5px 5px #888888;
right: 300px;
top: 250px;
text-align: justify;
-webkit-transition: all .75s;
font-size: large;
color: Black;
padding: 10px;
background: #D0D0D0;
opacity: 0;
}
#-webkit-keyframes myFirst {
0% {
right: 300px;
top: 160px;
background: #D0D0D0;
opacity: 0;
}
100% {
background: #909090;
:;
right: 300px;
top: 200px;
opacity: 1;
}
}
#littlebox1 {
top: 200px;
position: absolute;
display: inline-block;
}
.littlebox1-sentence {
font-size: large;
padding-bottom: 15px;
padding-top: 15px;
padding-left: 25px;
padding-right: 10px;
background: #D0D0D0;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
-webkit-transition: background .25s ease-in-out;
}
#bothcontainer:hover ~ #box1 {
-webkit-transition: all 0s;
background: #909090;
:;
right: 300px;
top: 200px;
-webkit-animation: myFirst .75s;
-webkit-animation-fill-mode: initial;
opacity: 1;
}
#bothcontainer:hover .littlebox1-sentence {
background: #909090
}
#bothcontainer:hover .triangle {
border-right: 25px solid #909090
}
.triangle {
position: relative;
width: 0;
height: 0;
border-right: 25px solid #D0D0D0;
border-top: 27px solid transparent;
border-bottom: 24px solid transparent;
right: 184px;
-webkit-transition: border-right .25s ease-in-out;
}
HTML
<body dir="rtl">
<div id="page">
<div id="bothcontainer">
<div id="littlebox1" class="littlebox1-sentence">put your mouse here</div>
<div id="littlebox1" class="triangle"></div>
</div>
<div id="box1"></div>
</div>
I want to add a border to the triangle, to .littlebox1-sentence.
The border will not change its color.
Here is a fiddle
I have come closer to finding the solution, but it still is not where I want it.
Fiddle
I'm not exactly sure what effect you're after, but I'd have a look at -webkit-filter. It allows you to add a shadow to "this element and any children it has, regardless of shape".
#littlebox1 {
top: 200px;
position: absolute;
display: inline-block;
-webkit-filter: drop-shadow(green -10px 0 10px);
}
http://jsfiddle.net/DyxA4/
Another solution: skip the border-based triangle and use three divs instead:
<div class="sign">
<div class="arrow"><div></div></div>
<p>Lorem ipsum dolor</p>
</div>
Basically, we use ".arrow div" to create the triangle, and ".arrow" the cut off the bits we don't need:
http://jsfiddle.net/k5J6M/1/
The triangle IS the border. You can't do what you're asking. Just make an image.

Resources