Hovering over btn should trigger display: block; on btn2 (which it does), then maintain this hover effect when I move the mouse below and outside of btn until I am able to click btn2 (which it currently doesn't).
I thought I could do this by using margin on btn, but that didn't work.
body {
background-color: #673ab7;
font-size: 30px;
}
.btn {
margin-bottom: 50px;
text-align: center;
line-height: 100px;
position: absolute;
left: 50%;
width: 100px;
height: 100px;
background-color: #00bcd4;
border-radius: 100%;
transition: all .2s ease-in-out;
&:hover {
transform:scale(1.05,1.05)
}
}
.btn2 {
position: absolute;
top: 110px;
left: 50.5%;
text-align: center;
line-height: 55px;
border-radius: 50px;
display: none;
width: 50px;
height: 50px;
background-color: black;
transition: all .2s ease-in-out;
&:hover {
transform:scale(1.05,1.05)
}
}
.btn:hover +.btn2{
transition: all .2s ease-in-out;
display: block;
position: absolute;
transform: scale(1.05,1.05);
transform: translate(20px);
}
.icon {
color: white;
}
.icon2 {
color: white;
width: 26px;
line-height: 20px;
}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<div class="container">
<i class="icon fa fa-link"></i>
<i class="icon2 fa fa-edit"></i>
</div>
Set your :hover css to the parent .container tag of both items so the hover rules are maintained when moving from one element to the next. This way you are maintaining the hover state when moving from child to child.
I also changed display:none; to visibility:hidden; and opacity:0|opacity:1 respectively. `display:none' isn't going to animate.
The animation time also allows for a short period of overlap (non :focus) when moving from one element to the other. With some keyframing you can make the move from one to the other a bit cleaner.
body {
background-color: #673ab7;
font-size: 30px;
}
.btn {
margin-bottom: 50px;
text-align: center;
line-height: 100px;
position: absolute;
left: 50%;
width: 100px;
height: 100px;
background-color: #00bcd4;
border-radius: 100%;
transition: all .2s ease-in-out;
&:hover {
transform:scale(1.05,1.05)
}
}
.btn2 {
position: absolute;
top: 110px;
left: 50.5%;
text-align: center;
line-height: 55px;
border-radius: 50px;
visibility:hidden;
opacity:0;
width: 50px;
height: 50px;
background-color: black;
transition: all .2s ease-in-out;
&:hover {
transform:scale(1.05,1.05)
}
}
.container:hover .btn +.btn2{
transition: all .2s ease-in-out;
visibility:visible;
opacity:1;
position: absolute;
transform: scale(1.05,1.05);
transform: translate(20px);
}
.icon {
color: white;
}
.icon2 {
color: white;
width: 26px;
line-height: 20px;
}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<div class="container">
<i class="icon fa fa-link"></i>
<i class="icon2 fa fa-edit"></i>
</div>
Related
I am trying to write code that mimics this animation as much as possible.
I have been going over keyframe animations & I think that they can be used to do what I need them to do.
I effectively want to have three things happen when the user hovers over the parent element. The first is the color
on the right side of the element will change dynamically (as in the picture & as in the example code), the
icon will animate into the picture & then the text will then animate.
I am new to programming & I am looking for some direction.
Example of finished product: https://imgur.com/a/bxV1V1B
DEMO
.wrapper {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
a {
display: block;
width: 200px;
height: 40px;
line-height: 40px;
font-size: 18px;
font-family: sans-serif;
text-decoration: none;
color: #333;
border: 2px solid #333;
letter-spacing: 2px;
text-align: center;
position: relative;
transition: all .35s;
}
a span {
position: relative;
z-index: 2;
}
a:after {
position: absolute;
content: "";
top: 0;
right: 0;
width: 0;
height: 100%;
background: green;
transition: all .35s;
}
a:hover:after {
width: 15%;
}
<div class="wrapper">
<span>Hover Me!</span>
</div>
Here you go. I made a CSS animation for you which will rotate and translate a new i that I have added into the HTML. I used font awesome for the check with the circle around it. Take a look:
.wrapper {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
a {
display: block;
width: 200px;
height: 40px;
line-height: 40px;
font-size: 18px;
font-family: sans-serif;
text-decoration: none;
color: #333;
border: 2px solid #333;
letter-spacing: 2px;
text-align: center;
position: relative;
transition: all .35s;
}
a span {
position: relative;
z-index: 2;
}
a:after {
position: absolute;
content: "";
top: 0;
right: 0;
width: 0;
height: 100%;
background: green;
transition: all .35s;
visibility: hidden;
}
a:hover:after {
width: 15%;
visibility: visible;
}
#check {
right: 2px;
top: 8px;
position: absolute;
display: none;
z-index: 3;
transition: right .35s;
}
a:hover #check {
animation:spin .35s linear;
display: block;
}
#keyframes spin {
0% {
transform: translate(25px) rotate(0deg);
}
100% {
transform: translate(0px) rotate(360deg);
}
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="wrapper">
<span>Hover Me!</span><i id="check"style="font-size:22px; color:lightgrey" class="fa fa-check-circle"></i>
</div>
I'm writing a code for the chat of my stream, but i got some problems... i want to rotate only the border of the chat box without move the text or the background. how can i do this? i have already read some post but did not solve my problem. i want to do something like that chat.
i use the StreamLabs.
English is not my mother tongue; please excuse any errors on my part.
I'm a beginner at the front end and these issues are taking away my peace.
#import url(https://fonts.googleapis.com/css?family=Open+Sans:600,700);
body {
background: $background_color;
color: $text_color;
}
html, body {
height: 600%;
overflow: hidden;
transform: translate(0px, -10px);
}
#log {
font: 90;
font-family: 'Montserrat', sans-serif;
position: absolute;
bottom: 0;
left: 0;
width: 60%;
box-sizing: border-box;
overflow: hidden;
padding: 10px 16px;
padding-top: 100px;
}
#log>div {
margin-bottom: 45px;
background: rgba(255, 255, 255, 0.1);
padding: 5px 10px 10px;
animation: fadeInDown .3s ease forwards, fadeOut 0.5s ease {message_hide_delay} forwards;
-webkit-animation: fadeInDown .3s ease forwards, fadeOut 0.5s ease {message_hide_delay} forwards;
border-radius: 8px;
}
#log>div.deleted {
visibility: hidden;
}
.meta {
display: table;
line-height: em;
transform: translate(-20px,-30px);
border-radius: 0px 05px 05px 05px;
border: 10px solid #ffd600;
background: #ffd600;
margin-bottom: -22px;
font-weight: 800;
}
.message {
word-wrap: break-word;
display: block;
padding-left: 6px;
line-height: em;
color:white;]
}
.name {
color: Black;
font-size: em;
text-transform: initial;
font-weight: 600;
}
.colon {
display: none;
}
.badge {
float: left;
padding-left: 2px;
padding-right: 7px;
padding-top: 2px;
height: 0.8em;
}
#log .emote {
background-repeat: no-repeat;
background-position: center;
padding: 0.1em;
background-size: contain;
}
#log .emote img {
display: inline-block;
height: 1em;
opacity: 0;
vertical-align: top;
}
<!-- item will be appened to this layout -->
<div id="log" class="sl__chat__layout">
</div>
<!-- chat item -->
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Merriweather" rel="stylesheet">
<script type="text/template" id="chatlist_item">
<div data-from="{from}" data-id="{messageId}">
<span class="meta" style="color: {color}">
<span class="badges">
</span>
<span class="name">{from}</span>
</span>
<span class="message">
{message}
</span>
</div>
</script>
You can add a new element to your html and style it to look like that border, or style a pseudo element like ::before or ::after to give you that look.
.tilted-border {
margin: 10px;
background: purple;
border-radius: 10px;
width: 200px;
height: 100px;
position: relative;
padding: 0;
}
.tilted-border:after {
content: '';
display: block;
position: absolute;
top: -5px;
left: -5px;
width: 100%;
height: 100%;
border: 5px solid red;
border-radius: 10px;
transform: rotate( 5deg);
pointer-events: none;
}
<div class="tilted-border"></div>
What you're trying to do is not possible. You cannot move the border of a div independently of the div and its content.
What you'll need to do is create bother div within the first div. Set the container div to position: relative and then absolutely position the new inner div to the edges of the container like so: position: absolute; top: 0; bottom: 0; left: 0; right: 0;. Then you can animate the border of the inner div while the content still sits within the container div free of the transform.
I have here a progress bar containing three html elements : a yellow block, a red block, and a text block,used as label for the progression.
demo : https://codepen.io/anon/pen/wEgJmL
<p class="pinim-pc-bar incomplete"><span class="pinim-pc-bar-fill" style="width:80%"><span class="pinim-pc-bar-fill-color pinim-pc-bar-fill-yellow"></span><span class="pinim-pc-bar-fill-color pinim-pc-bar-fill-red" style="opacity:0.2"></span><span class="pinim-pc-bar-text">8/10<i class="fa fa-refresh" aria-hidden="true"></i></span></span></p>
The red & yellow blocks are surimposed so they mix to a color that represent the percentage of progression (the red bar has a certain opacity set).
BUT my text element do not displays and I don't understand why...
Could anyone help ?
Simply add a negative z-index to the bars and z-index:0 to their container to keep them inside the same stacking context and make the text above.
.pinim-pc-bar {
position: relative;
display: block;
background-color: rgba(204, 204, 204, 0.4);
clear: both;
width: 100%;
height: 1.3em;
line-height: 1.3em;
}
.pinim-pc-bar .pinim-pc-bar-fill {
display: block;
height: 100%;
text-align: left;
-moz-transition: all 0.5s ease-out;
-o-transition: all 0.5s ease-out;
-webkit-transition: all 0.5s ease-out;
transition: all 0.5s ease-out;
position: relative;
z-index:0;
}
.pinim-pc-bar .pinim-pc-bar-fill .pinim-pc-bar-fill-color {
width: 100%;
height: 100%;
position: absolute;
z-index:-1;
}
.pinim-pc-bar .pinim-pc-bar-fill .pinim-pc-bar-fill-color.pinim-pc-bar-fill-yellow {
background-color: #FFE000;
}
.pinim-pc-bar .pinim-pc-bar-fill .pinim-pc-bar-fill-color.pinim-pc-bar-fill-red {
background-color: red;
}
.pinim-pc-bar .pinim-pc-bar-fill .pinim-pc-bar-text {
margin: auto;
display: block;
text-align: center;
}
.pinim-pc-bar .pinim-pc-bar-fill .pinim-pc-bar-text i.fa {
padding: 0 0.5em;
}
.pinim-pc-bar.color-light .pinim-pc-bar-text {
color: white;
}
.pinim-pc-bar.empty .pinim-pc-bar-fill {
width: 100% !important;
}
.pinim-pc-bar.empty .pinim-pc-bar-fill-color {
display: none;
}
.pinim-pc-bar.empty .pinim-pc-bar-text {
color: inherit;
font-size: 0.8em;
}
.pinim-pc-bar.incomplete .pinim-pc-bar-text {
text-align: right;
}
<p class="pinim-pc-bar incomplete"><span class="pinim-pc-bar-fill" style="width:80%"><span class="pinim-pc-bar-fill-color pinim-pc-bar-fill-yellow"></span><span class="pinim-pc-bar-fill-color pinim-pc-bar-fill-red" style="opacity:0.2"></span><span class="pinim-pc-bar-text">8/10<i class="fa fa-refresh" aria-hidden="true"></i></span></span></p>
<p>Hi! This progress bar (colored part) contains three html elements : a yellow block (<em>.pinim-pc-bar-fill-yellow</em>), a red block (<em>.pinim-pc-bar-fill-red</em>), and a text block (<em>.pinim-pc-bar-text</em>),used as label for the progression.</p>
<p>
The red & yellow blocks are surimposed so they mix to a color that represent the percentage of progression (the red bar has a certain opacity set).
</p>
<p>BUT Why is my text element not displayed ? Thanks !</p>
I have documented the CSS changes for .pinim-pc-bar-text. When elements are positioned absolute they're taken out of the document flow. The same then needs to happen for the text.
.pinim-pc-bar {
position: relative;
display: block;
background-color: rgba(204, 204, 204, 0.4);
clear: both;
width: 100%;
height: 1.3em;
line-height: 1.3em;
}
.pinim-pc-bar .pinim-pc-bar-fill {
display: block;
height: 100%;
text-align: left;
-moz-transition: all 0.5s ease-out;
-o-transition: all 0.5s ease-out;
-webkit-transition: all 0.5s ease-out;
transition: all 0.5s ease-out;
position: relative;
}
.pinim-pc-bar .pinim-pc-bar-fill .pinim-pc-bar-fill-color {
width: 100%;
height: 100%;
position: absolute;
}
.pinim-pc-bar .pinim-pc-bar-fill .pinim-pc-bar-fill-color.pinim-pc-bar-fill-yellow {
background-color: #ffe000;
}
.pinim-pc-bar .pinim-pc-bar-fill .pinim-pc-bar-fill-color.pinim-pc-bar-fill-red {
background-color: red;
}
.pinim-pc-bar .pinim-pc-bar-fill .pinim-pc-bar-text {
margin: auto;
display: block;
/* text-align: center; DOES NOT WORK */
/* ADDED */
position: absolute;
left: 50%;
transform: translateX(-50%);
/* END ADDED */
}
.pinim-pc-bar .pinim-pc-bar-fill .pinim-pc-bar-text i.fa {
padding: 0 0.5em;
}
.pinim-pc-bar.color-light .pinim-pc-bar-text {
color: white;
}
.pinim-pc-bar.empty .pinim-pc-bar-fill {
width: 100% !important;
}
.pinim-pc-bar.empty .pinim-pc-bar-fill-color {
display: none;
}
.pinim-pc-bar.empty .pinim-pc-bar-text {
color: inherit;
font-size: 0.8em;
}
.pinim-pc-bar.incomplete .pinim-pc-bar-text {
text-align: right;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<p class="pinim-pc-bar incomplete"><span class="pinim-pc-bar-fill" style="width:80%"><span class="pinim-pc-bar-fill-color pinim-pc-bar-fill-yellow"></span><span class="pinim-pc-bar-fill-color pinim-pc-bar-fill-red" style="opacity:0.2"></span><span class="pinim-pc-bar-text">8/10<i class="fa fa-refresh" aria-hidden="true"></i></span></span>
</p>
Use this CSS code:
.pinim-pc-bar.incomplete .pinim-pc-bar-text{position: relative;}
Here you can see my issue. I assume it has to do with the block and inline-block. I want to cleanly make the text appear when hovering over the area. Preferably all in CSS. If anyone can point me in the right direction, that'd be amazing. Thank you!
HTML
<div class="contact-icon icongrow" id="github">
<span class="fa fa-github icon"></span>
<span class="contact-icon-text">#username</span>
</div>
CSS
#github {
border-radius: 15px 10px;
padding: 8px 5px 5px 8px;
background: #000000;
color: #FFFFFF;
}
.icon {
float:none;
}
.icongrow {
font-size:24px;
width: 24px;
transition:width 1s;
display: block;
}
.icongrow:hover {
font-size: 28px;
width: 300px;
}
.icongrow:hover .contact-icon-text {
display: inline-block;
}
.contact-icon-text {
display: none;
}
https://jsfiddle.net/sfpfka64/
Add white-space: nowrap to .icongrow
.icongrow {
font-size:24px;
width: 24px;
transition:width 1s;
display: block;
white-space: nowrap;
}
and add an opacity transition to contact-icon-text :
.icongrow:hover .contact-icon-text {
opacity: 1;
}
.contact-icon-text {
opacity: 0;
display:inline-block;
transition: all 0.5s;
}
Also make the font-size on hover same as the initial font-size to provide more smoothness :
.icongrow:hover {
font-size: 24px;
width: 300px;
}
Snippet
#github {
border-radius: 15px 10px;
padding: 8px 5px 5px 8px;
background: #000000;
color: #FFFFFF;
}
.icon {
float:none;
}
.icongrow {
font-size:24px;
width: 24px;
transition:width 1s;
display: block;
white-space: nowrap;
}
.icongrow:hover {
font-size: 24px;
width: 300px;
}
.icongrow:hover .contact-icon-text {
opacity: 1;
}
.contact-icon-text {
opacity: 0;
display:inline-block;
transition: all 0.5s;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="contact-icon-container">
<div class="contact-icon icongrow" id="github">
<span class="fa fa-github icon"></span>
<span class="contact-icon-text">#username</span>
</div>
</div>
Just add the following rules to the .icongrow
white-space: nowrap;
overflow: hidden;
Working fiddle: https://jsfiddle.net/yvqga0ja/
An easy way would be to put your "contact-icon-text" as a position absolute, so that he would always be placed at the right place.
Demo
.contact-icon-container{
position:relative;
}
.contact-icon-text {
position: absolute;
top: 50%;
transform: translateY(-50%);
right: 10px;
opacity: 0;
}
.icongrow:hover .contact-icon-text {
opacity: 1;
transition: .3s ease-in;
You can add transition-delay in order to make your text appear a bit later, but you get the way I would do it :)
I've tried creating a ripple effect on hover over with a button, the only problem I have is that the text shakes/rattles/shivers when I hover over it, I want it to stay still for a smooth transition. Any ideas on how to stop this?
a {
display: block;
position: relative;
width: 300px;
height: 50px;
background: rgba(0, 0, 255, .2);
text-decoration: none;
text-align: center;
overflow: hidden;
margin: 10% auto;
}
p,
span:first-of-type,
span:last-of-type {
position: absolute;
margin: 0;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 0;
height: 0;
border-radius: 50%;
transition: all .3s;
}
span:first-of-type {
transition-delay: .1s;
z-index: 1;
}
span:last-of-type {
transition-delay: .2s;
z-index: 2;
}
span.cta {
color: #33C;
text-transform: uppercase;
font-family: Arial;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 300px;
display: block;
transition: color .3s;
z-index: 3;
}
a:hover p,
a:hover span:first-of-type,
a:hover span:last-of-type {
width: 110%;
height: 660%;
border-radius: 50%;
background: rgba(0, 0, 255, .2);
}
a:hover span:first-of-type,
a:hover span:last-of-type {
width: 100%;
height: 100%;
}
a:hover p span {
color: #FFF;
}
<a href="#">
<p>
<span></span>
<span class="cta">Shop the Trend</span>
<span></span>
</p>
</a>
N.B. It's fine in IE11, it happens in every other browser.
Here you go...Modified HTML[added button text inside div and applied new class "textCta" to it]
<span class="cta"><div class="textCta">Shop the Trend</div></span>
CSS
.textCta {
color:#33C;
text-transform:uppercase;
font-family:Arial;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
width: 300px;
display: block;
transition: color .3s;
z-index: 3;
}
Demo
By deleting the p tags and placing the actual text within a div, I managed to stop the shivering and still keep the background effect the same.
Thanks to Nofi for their help.
<a href="#">
<span></span>
<div class="cta">Shop the Trend</div>
<span></span>
</a>