Animated mask and hide circle on hover with css - css

I wanna make info box with this design.
This design is important to me. When mouse is over the circle, I need some animation and transform design to this...
jsFiddle Example :
.wrapper{
width:400px;
height:200px;
background: white;
position: relative;
}
.mask {
width: 100%;
height: 100%;
background: green;
background-size: cover;
transition: 0.4s ease;
clip-path: circle(80px at 50% 50%);
position: relative;
}
.mask:hover {
clip-path: circle(100% at 50% 50%);
}
.wrapper:after {
content: ' ';
display: block;
position: relative;
width: 160px;
height: 160px;
top: calc(-50% - 83px);
left: calc(50% - 83px);
border-radius: 50%;
background:transparent;
border: 3px solid #fff;
box-shadow: 0px 0px 6px #aaa;
pointer-events: none;
}
<div class="wrapper">
<div id="map-canvas" class="mask">
</div>
</div>
But I don't know how to hide the circle.
Is there any solution how to make and hide that circle with border and shadow ?

Try use transition and opacity for wrapper:after
You would want to transparent pseudo element after on hover and target it with .wrapper:hover:after.
.wrapper{
width:400px;
height:200px;
background: white;
position: relative;
}
.mask {
width: 100%;
height: 100%;
background: green;
background-size: cover;
transition: 0.4s ease;
clip-path: circle(80px at 50% 50%);
position: relative;
}
.mask:hover {
clip-path: circle(100% at 50% 50%);
}
.wrapper:after {
content: ' ';
display: block;
position: relative;
width: 160px;
height: 160px;
top: calc(-50% - 83px);
left: calc(50% - 83px);
border-radius: 50%;
background:transparent;
border: 3px solid #fff;
box-shadow: 0px 0px 6px #aaa;
pointer-events: none;
opacity:1;
transition: all 0.5s forwards ; /*added */
}
.wrapper:hover:after{
opacity:0 ; /*added */
}
<div class="wrapper">
<div id="map-canvas" class="mask">
</div>
</div>
also if you want some animation on hover out you can use bellow code:
.wrapper{
width:400px;
height:200px;
background: white;
position: relative;
}
.mask {
width: 100%;
height: 100%;
background: green;
background-size: cover;
transition: 0.4s ease;
clip-path: circle(80px at 50% 50%);
position: relative;
}
.mask:hover {
clip-path: circle(100% at 50% 50%);
}
.wrapper:after {
content: ' ';
display: block;
position: relative;
width: 160px;
height: 160px;
top: calc(-50% - 83px);
left: calc(50% - 83px);
border-radius: 50%;
background:transparent;
border: 3px solid #fff;
box-shadow: 0px 0px 6px #aaa;
pointer-events: none;
transition: all 0.5s ease-in ;
}
.wrapper:hover:after{
opacity:0 ;
transition: all 0.5s forwards ; /* added */
}
<div class="wrapper">
<div id="map-canvas" class="mask">
</div>
</div>

You can just unset the border and box-shadow on :hover and transition that change, too, if you want.
.wrapper{
width:400px;
height:200px;
background: white;
position: relative;
}
.mask {
width: 100%;
height: 100%;
background: green;
background-size: cover;
clip-path: circle(80px at 50% 50%);
position: relative;
}
.mask, .wrapper:after {
transition: 0.4s ease;
}
.wrapper:hover .mask {
clip-path: circle(100% at 50% 50%);
}
.wrapper:hover:after {
border: 0;
box-shadow: none;
}
.wrapper:after {
content: ' ';
display: block;
position: relative;
width: 160px;
height: 160px;
top: calc(-50% - 83px);
left: calc(50% - 83px);
border-radius: 50%;
background:transparent;
border: 3px solid #fff;
box-shadow: 0px 0px 6px #aaa;
pointer-events: none;
}
<br/>
<br/>
<div class="wrapper">
<div id="map-canvas" class="mask">
</div>
</div>

Related

Duplicate image and set hover CSS

I want to make the following animation:
One div with 2 same arrows and on hover first arrow should move on left/right. I tried to do it, but it unsuccessfully. I'm setting background with 2 images, but how I can set animation for 1 of the images like the gif?
.arrow-right2 {
content: "";
background: transparent url(https://i.imgur.com/u7cYXIo.png) 0 -185px no-repeat, transparent url(https://i.imgur.com/u7cYXIo.png) 0 -185px no-repeat;
height: 35px;
position: absolute;
top: -5%;
left: 0;
width: 35px;
}
Try to use 2 different divs with the same arrows, with position absolute and use this to overlap the two arrows. If you can, use a single image, not a sprite. Then apply the effect on hover on one of the images.
body {
background: red;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
display: flex;
justify-content: center;
align-items: center;
width: 50px;
height: 50px;
position: relative;
}
.arrow1 {
background: url('https://i.imgur.com/u7cYXIo.png') no-repeat -17px -199px;
width: 12px;
height: 24px;
display: block;
left: 0;
position: absolute;
}
.arrow2 {
background: url('https://i.imgur.com/u7cYXIo.png') no-repeat -17px -199px;
width: 12px;
height: 24px;
display: block;
position: absolute;
transition: all 0.4s;
left: 0;
}
.arrow2:hover {
left: -10px;
transition: all 0.4s;
}
<div class="container">
<div class="arrow1">
</div>
<div class="arrow2">
</div>
</div>
You can adjust background-position like below. You start with a different position for each one then you make them the same:
.arrow {
background:
url(https://i.imgur.com/u7cYXIo.png) -10px -185px,
url(https://i.imgur.com/u7cYXIo.png) 10px -185px,
red;
background-repeat:no-repeat;
height: 50px;
width: 50px;
transition:all 0.5s;
}
.arrow:hover {
background-position:10px -185px;
}
<div class="arrow"></div>
Or the opposite
.arrow {
background:
url(https://i.imgur.com/u7cYXIo.png),
url(https://i.imgur.com/u7cYXIo.png),
red;
background-position:10px -185px;
background-repeat:no-repeat;
height: 50px;
width: 50px;
transition:all 0.5s;
}
.arrow:hover {
background-position:
-10px -185px,
10px -185px;
}
<div class="arrow"></div>
And if you want to adjust coloration you can consider mix-blend-mode
.arrow {
background:
url(https://i.imgur.com/u7cYXIo.png),
url(https://i.imgur.com/u7cYXIo.png),
#000;
background-position:10px -185px;
background-repeat:no-repeat;
height: 50px;
width: 50px;
transition:all 0.5s;
position:relative;
}
.arrow:before {
content:"";
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
background: red;
mix-blend-mode: multiply;
opacity:0;
transition:all 0.5s;
}
.arrow:hover {
background-position:
-10px -185px,
10px -185px;
}
.arrow:hover:before {
opacity:1;
}
<div class="arrow"></div>

:before and :after pseudo elements to receive transition effect

I am trying to build a parallelogram background that only appears on hover in a menu item. For the shape, I am using :before and :after pseudo-elements, however I cannot apply the same transition effect on them. Does anyone knows what could I do to solve this problem?
Here is the code until the moment:
div {
float:left;
background-color:#fff;
margin: 20px;
transition:.5s;
}
.testClass {
margin-top: 0px;
margin-left: 0px;
padding: 5px 10px;
display: block;
background-repeat: no-repeat;
background: #fff;
position: relative;
transition:.5s;
}
.testClass:hover {
background: gold;
transition:.5s;
}
.testClass:hover:before {
content: '';
position: absolute;
top:0;
left:-15px;
width: 0px;
height: 0px;
border-style: solid;
border-width: 0 0 29px 15px;
border-color: transparent transparent gold transparent;
}
.testClass:hover:after {
content: '';
position: absolute;
top:0;
right:-15px;
width: 0px;
height: 0px;
border-style: solid;
border-width: 30px 15px 0 0;
border-color: gold transparent transparent transparent;
}
<div >
<div class="testClass">HOME</div>
<div class="testClass">ABOUT US</div>
<div class="testClass">CONTACT</div>
<div class="testClass">LOGIN</div>
<div class="testClass">SERVICES</div>
</div>
What about an easier way with only one element to create the shape:
div {
float: left;
margin: 20px;
transition: .5s;
}
.testClass {
margin-top: 0px;
margin-left: 0px;
padding: 5px 10px;
display: block;
background: #fff;
position: relative;
transition: .5s;
z-index: 0;
}
.testClass:before {
content: '';
position: absolute;
z-index: -1;
top: 0;
left: -10px;
right: -10px;
bottom: 0;
opacity: 0;
background: gold;
transform: skew(-20deg);
transition: .5s;
}
.testClass:hover::before {
opacity: 1;
}
<div>
<div class="testClass">HOME</div>
<div class="testClass">ABOUT US</div>
<div class="testClass">CONTACT</div>
<div class="testClass">LOGIN</div>
<div class="testClass">SERVICES</div>
</div>

Span position absolute is not centered with top and left

I want to create a "X" with css spans and position absolute, but the spans aren't centered even if they should.
The container has the font-size of 1px. and a height and width of 100em. Therefore I can use 1em as 1% of the parents size.
I used transform-origin: 0px 5em; on the span, to rotate it without changing the starting point. The Element starts in 20% top and left (20em) and ends in 80% (top and left).
To get the required width i simply calculated: Square root( square of (60) * 2) (Pythagorean theorem) (60 because start and end 20 -- 100-20*2)
But for some reason the X is clearly not centered. Do you know what i did wrong?
body
{
margin: 0px;
}
.check
{
font-size: 1px;
position: relative;
height: 100em;
width: 100em;
background-color: white;
border-radius: 50%;
transition: .3s;
box-shadow: 0px 0px 10px red inset;
}
.check span
{
position: absolute;
display: block;
height: 10em;
width: 0px;
background-color: #00FF00;
transition:.3s;
}
.check.red span
{
background-color: #FF0000;
transform-origin: 0px 5em;
transform: rotate(45deg);
top: 20em;
left: 20em;
}
.check.red span:nth-of-type(2)
{
transform: rotate(135deg);
top: 20em;
left: 80em;
}
.check.red:hover span
{
width: 84.852813742em;
}
<body>
<div class="check red">
<span></span>
<span></span>
</div>
</body>
This isn't an automatic solution, but changing some values in your css i solved it:
body
{
margin: 0px;
}
.check
{
font-size: 1px;
position: relative;
height: 100em;
width: 100em;
background-color: white;
border-radius: 50%;
transition: .3s;
box-shadow: 0px 0px 10px red inset;
}
.check span
{
position: absolute;
display: block;
height: 10em;
width: 0px;
background-color: #00FF00;
transition:.3s;
}
.check.red span
{
background-color: #FF0000;
transform-origin: 0px 5em;
transform: rotate(45deg);
top: 18em;
left: 22em;
}
.check.red span:nth-of-type(2)
{
transform: rotate(135deg);
top: 18em;
left: 78em;
}
.check.red:hover span
{
width: 78em;
}
<body>
<div class="check red">
<span></span>
<span></span>
</div>
</body>
There are a few things you can do to make life easier here.
Firstly you can transform origin using a percentage, which means you don't need to calculate it yourself.
You can also position using a percentage, then offset using a transform (again with a percentage) to center no matter the size.
You can also set the width of the cross using a percentage, which will take it size from its parent.
Update:
Change the cross to animate from the top, rather than the center by using background gradients.
.check
{
position: relative;
height: 200px;
width: 200px;
background-color: white;
border-radius: 50%;
box-shadow: 0px 0px 10px red inset;
}
.check span
{
position: absolute;
display: block;
height: 20px;
width: 0%;
background: linear-gradient(to right, white 50%, red 50%);
background-size: 200% 100%;
background-position: left bottom;
top: 50%;
left: 50%;
transform-origin: center;
transition: background 0.3s ease;
}
.check.red span
{
transform: translate(-50%, -50%) rotate(-45deg);
}
.check.red span:last-child
{
transform: translate(-50%, -50%) rotate(-135deg);
}
.check.red:hover span
{
background-position: right bottom;
width: 70%;
}
<div class="check red">
<span></span>
<span></span>
</div>
Try this
use margin-top:-0.5rem;
.check span
{
position: absolute;
display: block;
height: 10em;
width: 0px;
background-color: #00FF00;
transition:.3s; margin-top:-0.5rem;
}
body
{
margin: 0px;
}
.check
{
font-size: 1px;
position: relative;
height: 100em;
width: 100em;
background-color: white;
border-radius: 50%;
transition: .3s;
box-shadow: 0px 0px 10px red inset;
}
.check span
{
position: absolute;
display: block;
height: 10em;
width: 0px;
background-color: #00FF00;
transition:.3s; margin-top:-0.5rem;
}
.check.red span
{
background-color: #FF0000;
transform-origin: 0px 5em;
transform: rotate(45deg);
top: 20em;
left: 20em;
}
.check.red span:nth-of-type(2)
{
transform: rotate(135deg);
top: 20em;
left: 80em;
}
.check.red:hover span
{
width: 84.852813742em;
}
<body>
<div class="check red">
<span></span>
<span></span>
</div>
</body>

CSS round div fill-in on hover

I tried to make a little effect while hovering a round div, but I couldn't find how actually to make the fill in in a round shape too.
As you can see the fill in is in a square shape, and I would like to have it in the shape of my div (round in this case)
Is there a solution to that in CSS?
.circle {
height: 50px;
width: 50px;
margin: 35px;
border: 3px solid blue;
background-image: linear-gradient(blue, blue);
background-repeat: no-repeat;
transition: background-size .5s, color .5s;
background-size: 0 0;
background-position: 50% 50%;
border-radius: 30px;
}
.circle:hover {
background-size: 100% 100%;
color: blue;
}
<div class="circle"></div>
You can use radial-gradient or box-shadow
box-shadow
.circle {
height: 50px;
width: 50px;
margin: 35px;
border: 3px solid blue;
background: blue;
transition: box-shadow .5s, color .5s;
background-size: 0 0;
background-position: 50% 50%;
border-radius: 30px;
box-shadow: inset 0 0 0 50px white
}
.circle:hover {
box-shadow: inset 0 0 0 0px white;
color: blue;
}
<div class="circle">
</div>
radial-gradient
.circle {
height: 50px;
width: 50px;
margin: 35px;
border: 3px solid blue;
background-image: radial-gradient(circle at center , blue 50%, transparent 50%);
background-repeat: no-repeat;
transition: background-size .5s, color .5s;
background-size: 0 0;
background-position: 50% 50%;
border-radius: 30px;
}
.circle:hover {
background-size: 200% 200%;
color: blue;
}
<div class="circle">
</div>
You can fill the circle and set animations with a pseudo element.
.circle {
height: 50px;
width: 50px;
border: 3px solid blue;
border-radius: 50%;
margin: 35px;
position: relative;
}
.circle:before {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
content: "";
background: blue;
border-radius: 50%;
width: 0;
height: 0;
transition: all .5s;
}
.circle:hover:before {
width: 100%;
height: 100%;
}
<div class="circle"></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