Is it possible to create an animation with CSS so that a given element (in the example, an h2 tag) when hovered moves a bit and fades out, and come back a few moments later fading in with a larger font-size.
Ideally:
This would occur on hover and the inverse when no longer hovering.
Without specifying the initial font size (in the example 2rem).
I've been trying some solutions with animations but so far nothing close to what I'm looking for.
Thanks
Edit: added short animation of what I was looking for (line is there for geometric reference of the text's position):
Edit2: the GIF if looping, but the text is supposed to remain large while the container element is hovered.
:root {
height: 100%;
background-color: lightgrey;
padding: 30px;
text-align: center;
}
h2 {
font-family: Arial;
font-size: 2rem;
}
:root:hover h2 {
font-size: 5rem;
animation: text 1s forwards ease-out;
}
#keyframes text {
0% {
transform: translateY(-30px);
opacity: 1;
}
50% {
opacity: 0;
}
100% {
}
}
<h2>TEXT</<h2>
Thank you for providing a snippet. Not sure this is what you opted for. I added a flex container to center the text, but this is optional.
:root {
height: 100%;
background-color: lightgrey;
padding: 30px;
text-align: center;
}
h2 {
font-family: Arial;
}
:root:hover h2 {
animation: text 1s forwards ease-out;
}
#keyframes text {
0% {
transform: translateY(0px);
opacity: 1;
}
25% {
transform: translateY(-30px);
opacity: 0;
font-size: 1rem;
}
50% {
opacity: 0;
}
75% {
opacity: 0;
transform: translateY(0px);
}
100% {
font-size: 5rem;
opacity: 1;
}
}
<div style="height: 150px; display:flex; align-items: center; justify-content: center;">
<h2>TEXT</h2>
</div>
UPDATE: Attempting doing the gif animation
:root {
height: 100%;
background-color: lightgrey;
padding: 30px;
text-align: center;
}
h2 {
font-family: Arial;
font-size: 2em;
margin-bottom: 0;
line-height: 1;
position: absolute;
bottom: 0;
text-align: center;
width: 100%
}
:root:hover h2 {
animation: text 1s forwards ease-out;
}
#keyframes text {
0% {
transform: translateY(0px);
opacity: 1;
}
25% {
transform: translateY(+50px);
opacity: 0;
}
50% {
opacity: 0;
font-size: 2em;
}
75% {
opacity: 0;
font-size: 5em;
transform: translateY(+50px);
}
100% {
font-size: 5rem;
transform: translateY(0px);
opacity: 1;
}
}
<div style="height: 100px; position: relative; border: 1px solid red;">
<h2>TEXT</h2>
</div>
<hr>
The root element confuses me. Nevertheless, you can add a font-size and oppacity 0 at 50 percent. The element will return to the original place afterwards. The margin-top keeps the element with the bigger font size in place. Not sure if this is the ideal solution.
Maybe just personal preference. I have changed the animation to ease-in-out, see https://www.w3schools.com/css/css3_transitions.asp
:root {
height: 100%;
background-color: lightgrey;
text-align: center;
}
h2 {
font-family: Arial;
padding: 0px;
}
:root:hover h2 {
animation: text 3s forwards ease-in-out;
}
#keyframes text {
0% {
opacity: 1;
}
50% {
opacity: 0;
font-size: 2rem;
}
100% {
opacity: 1;
margin-top: 1.5rem;
font-size: 3.5rem;
}
}
<h2>TEXT</<h2>
Hi I have a problem trying to getting the animation at the left hand side of the button when user mouse over the button. One of the example that explain as below:
HTML:
<div class="block">
<div class="normal">
<span>Follow me...</span>
</div>
<a target="_BLANK" class="hover" href="http://twitter.com/benoitboucart" title="My twitter profile">
on Twitter
</a>
CSS:
/**
* CSS3 balancing hover effect
* Read the tutorial here: http://webbb.be/blog/little-css3-3d-hover-effects/
*/
body {background: #f06;background: linear-gradient(45deg, #f06, yellow);min-height: 100%;}
.block {
width: 150px; color: #fff; margin: 30px auto; text-transform: uppercase; text-align: center; font-family: Helvetica;
position: relative;
perspective: 350;
}
.block .normal {
background: gray; padding: 15px; cursor: pointer;
position:relative; z-index:2;
}
.block .hover {
background: #00aced; margin-top:-48px; padding: 15px; display: block; color: #fff; text-decoration: none;
position: relative; z-index:1;
transition: all 250ms ease;
}
.block:hover .normal {
background: #0084b4;
}
.block:hover .hover {
margin-right: 0;
transform-origin: top;
/*
animation-name: balance;
animation-duration: 1.5s;
animation-timing-function: ease-in-out;
animation-delay: 110ms;
animation-iteration-count: 1;
animation-direction: alternate;
*/
animation: balance 1.5s ease-in-out 110ms 1 alternate;
}
#keyframes balance {
0% { margin-top: 0; }
15% { margin-top: 0; transform: rotateX(-50deg); }
30% { margin-top: 0; transform: rotateX(50deg); }
45% { margin-top: 0; transform: rotateX(-30deg); }
60% { margin-top: 0; transform: rotateX(30deg); }
75% { margin-top: 0; transform: rotateX(-30deg); }
100% { margin-top: 0; transform: rotateX(0deg);}
}
https://jsfiddle.net/9dwk8vzg/
Original link:http://dabblet.com/gist/5559193
But for this example is at the bottom instated of at the left hand side of the button, I tried using margin-right and padding-left still unable to get the mouse over appeal div tag to be on the right hand side, may I know what do I miss to get the div tag to appeal on the right hand side/
/**
* CSS3 balancing hover effect
* Read the tutorial here: http://webbb.be/blog/little-css3-3d-hover-effects/
*/
body {background: #f06;background: linear-gradient(45deg, #f06, yellow);min-height: 100%;}
.block {
width: 150px; color: #fff; margin: 30px auto; text-transform: uppercase; text-align: center; font-family: Helvetica;
position: relative;
perspective: 350;
}
.block .normal {
width: 100%;
background: gray; padding: 15px; cursor: pointer;
position:relative; z-index:2;
}
.block .hover {
width: 100%;
background: #00aced;
padding: 15px;
display: block;
position:absolute;
color: #fff;
text-decoration: none;
z-index:1;
transition: all 250ms ease;
right: -30px;
top: 0;
}
.block:hover .normal {
background: #0084b4;
}
.block:hover .hover {
right: 100%;
transform-origin: top;
/*
animation-name: balance;
animation-duration: 1.5s;
animation-timing-function: ease-in-out;
animation-delay: 110ms;
animation-iteration-count: 1;
animation-direction: alternate;
*/
animation: balance 1.5s ease-in-out 110ms 1 alternate;
}
#keyframes balance {
15% { width: 95%; }
30% { width: 105%; }
45% { width: 97%; }
60% { width: 103%; }
75% { width: 97%; }
100% { width: 100%; }
}
<div class="block">
<div class="normal">
<span>Follow me...</span>
</div>
<a target="_BLANK" class="hover" href="http://twitter.com/benoitboucart" title="My twitter profile">
on Twitter
</a>
</div>
Im struggling a bit with this project that I am working on. Essentially I have a chat interface built in angular, im having a problem getting the CSS styling right. At the moment the chat starts at the top, then scrolls down off the screen as the conversation grows. I can scroll with the conversation but this isnt very good UX.
I am trying to make it so the 'Send Message' box starts in the bottom third of the screen and is fixed. Then, as the conversation grows, the messages move upwards/away instead of downwards. Ideally I want this in a container that disappears (behind a header, etc).
I've been trying to wrap my brain around this for the past few days with not much luck. CSS isnt really a strong point of mine. Any help would be greatly appreciated
CSS & Image of current setup below (there is also a separate styling sheet but this is only for the button/message stylings:
<body><style>
body { background: #FFFFFF; color: #727272; }
h1, h2, h3, h4, { background: #FFFFFF; color: #212121; } body { background: #FFFFFF; color: #727272; }
html, body, form, strong, button, small, input, p, div, h1, h2, h3, h4
{ outline: 0; margin: 0; padding: 0; border: 0; font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; line-height: 1.4em; font-size: 100%; } !important;
a, a:active
{ color: #F8F8F8; text-decoration: none; }
a:hover { text-decoration: underline; }
button,
a { cursor: pointer; } strong { font-weight: 500; }
p, h1, h2, h3, h4 { margin-top: 1em; margin-bottom: 1em; }
h1, h2, h3, h4 { font-weight: 200; font-size: 32px; }
html, body, p, div { font-weight: 200; font-size: 17px; } .clear { clear: both }
.container { padding-right: 7vw; padding-left: 7vw; margin-right: auto; margin-left: auto; height: 100vh; }
</style><style>
/* .header { overflow: hidden; position: relative; min-height: 100vh; padding-bottom: 0vh; text-align: center; color: #F8F8F8; background: linear-gradient( to left, rgba(122,214,184,0.0) 0%, rgba(122,214,184,0.7) 100% ), linear-gradient( to bottom, rgb(60,240,80) 0%, rgb(122,214,184) 100% ); } */
.header { overflow: hidden; position: relative; min-height: 100vh; padding-bottom: 0vh; text-align: center; color: #F8F8F8; background: linear-gradient( to left, rgba(204,52,148,0.0) 0%, rgba(239,45,86,0.7) 100% ), linear-gradient( to bottom, rgb(204,52,148) 0%, rgb(204,52,148) 100% ); }
input::-webkit-input-placeholder { color: rgba(200,255,255,0.5) !important; } .header .signup { margin-top: 4em; } .header
input { background: transparent; color: #F8F8F8; border: 0; border-bottom: 1px solid rgba(255,255,255,0.8); line-height: 2em; font-size: 1.4em; text-align: center; width: 12em; }
/* .angularjs-chat-bubble-white { position: absolute; display: inline-block; background: transparent url(https://i.imgur.com/3Sdc2xD.png); background-size: 100%; background-repeat: no-repeat; } */
.bothello-bubble { position: absolute; display: inline-block; background: transparent url(https://i.imgur.com/kN9kf2o.png); background-size: 100%; background-repeat: no-repeat; }
.header .bubble-one { top: 15vh; left: 10vw; width: 30px; height: 30px; opacity: 0.1; transform-origin: 70% 400%; animation: bubble-move 3s ease-in-out 0s infinite alternate; }
.header .bubble-two { top: 44vh; left: 6vw; width: 100px; height: 100px; opacity: 0.1; transform-origin: 60% 400%; animation: bubble-move 4s ease-in-out 0s infinite alternate; }
.header .bubble-three { top: 75vh; left: 22vw; width: 20px; height: 20px; opacity: 0.2; transform-origin: 30% 120%; animation: bubble-move 2s ease-in-out 0s infinite alternate; }
.header .bubble-four { top: 14vh; left: 28vw; width: 15px; height: 15px; opacity: 0.1; transform-origin: 20% 400%; animation: bubble-move 2s ease-in-out 0s infinite alternate; }
.header .bubble-five { top: 30vh; left: 66vw; width: 14px; height: 14px; opacity: 0.2; transform-origin: 90% 100%; animation: bubble-move 5s ease-in-out 0s infinite alternate; }
.header .bubble-six { top: 8vh; left: 75vw; width: 23px; height: 23px; opacity: 0.2; transform-origin: 80% 200%; animation: bubble-move 2s ease-in-out 0s infinite alternate; }
.header .bubble-seven { top: 33vh; left: 84vw; width: 120px; height: 120px; opacity: 0.2; transform-origin: 100% 90%; animation: bubble-move 6s ease-in-out 0s infinite alternate; }
.header .bubble-eight { top: 72vh; left: 85vw; width: 360px; height: 360px; opacity: 0.2; transform-origin: -100% 100%; animation: bubble-move 7s ease-in-out 0s infinite alternate; }
/* .messagebox { padding-top: 90vh; position: fixed;} */
#keyframes bubble-move { 0% { opacity: 0.6; transform: scale(1.0) rotate(-8deg) translate(-1px,-2px); } 70% { opacity: 0.3; transform: scale(1.04) rotate(10deg) translate(2px,1px); } 100% { opacity: 0.4;
transform: scale(0.94) rotate(-18deg) translate(-3px,-1px); } }
</style>
<div class="header">
<!-- <div class="container"> -->
<div class="bothello-bubble bubble-one"></div>
<div class="bothello-bubble bubble-two"></div>
<div class="bothello-bubble bubble-three"></div>
<div class="bothello-bubble bubble-four"></div>
<div class="bothello-bubble bubble-five"></div>
<div class="bothello-bubble bubble-six"></div>
<div class="bothello-bubble bubble-seven"></div>
<div class="bothello-bubble bubble-eight"></div>
<div class="container">
<ng-container *ngFor="let message of messages | async">
<div class="message" [ngClass]="{ 'from': message.sentBy === 'bot',
'to': message.sentBy === 'user' }">
{{ message.content }}
</div>
</ng-container>
<div class="messagebox">
<label for="nameField">Your Message</label>
<input [(ngModel)]="formValue" (keyup.enter)="sendMessage()" type="text">
<button (click)="sendMessage()">Send</button>
</div>
<!-- </div> -->
</div>
</div>
</body>
Thanks so much.
Jay
You're looking for:
.container {
display: flex;
flex-direction: column;
}
.container>ng-container {
flex-grow: 1;
overflow: auto;
}
.container>.messagebox {
flex-shrink: 0;
margin-bottom: 3px;
}
You'll also need a small function to scroll <ng-container> to bottom whenever a message gets added to chat, something along these lines:
function scrollToBottom() {
let elem = document.querySelector('ng-container');
elem.scrollTop = elem.scrollHeight;
}
I don't know for sure what are best practices for manipulating DOM nodes in Angular2 (and above) and if there are any favored techniques over .querySelector.
Also note .querySelector can (and should) be used on any DOM node, so you probably want to use it on your ViewContainer rather than on the entire document.
But, since you haven't posted anything related to the JS part, I can't help you more there.
Can I flash a div using only CSS? I would like this div to flash two colors.
.chat-window .msg-container-base .notification-message-unread{
float: right;
font-size: 10px;
color: #666;
background: white;
padding-left: 10px;
}
Here you go:
.notification-message-unread {
float: right;
font-size: 10px;
color: #666;
background: white;
padding-left: 10px;
display: block;
position: relative;
width: 200px;
height: 200px;
background-color: red;
animation: blinker 1s linear infinite;
}
#keyframes blinker {
50% {
background-color: blue;
}
}
<div class="notification-message-unread"></div>
For this you can use CSS keyframe animations.
.box {
height: 500px;
width: 500px;
animation: animationFrames 5s infinite;
}
#keyframes animationFrames{
0% {
background-color: blue;
}
15% {
background-color: red;
}
30% {
background-color: orange;
}
45% {
background-color: purple;
}
60% {
background-color: green;
}
75% {
background-color: pink;
}
100% {
background-color: black;
}
}
<div class="box"></div>
In the .box class I'm using the animation property to link to an animation keyframe called animationFrames. I'm also defining how long I want this animation to play for, in the example above it's 5s and set to infinite so it repeats forever. The keyframe portion sets what CSS you want to apply to the animation at what percent in the animation, for example at 15% of 5 seconds it will turn red.
You can learn more about CSS keyframe animations here and here.
As per your specific example this code should work (I added a height property just so you could see it)
.chat-window {
float: right;
font-size: 10px;
color: #666;
background: white;
padding-left: 10px;
animation: animationFrames 2s infinite;
height: 500px;
}
#keyframes animationFrames{
50% {
background-color: orange;
}
}
<div class="chat-window"></div>
I need to have span with text aligned in the center.
Previously I have used line-height for this purpose, but in this case the text for some items are longer and this doesn't work any more.
JSFiddle: http://jsfiddle.net/4jSdu/
HTML:
<ul>
<li><a><span>Short</span></a>
</li>
<li><a><span>Why Should I Monitor?</span></a>
</li>
</ul>
CSS:
ul {
position: relative;
overflow: hidden;
}
span {
background-color: rgba(216, 25, 11, 0.75);
display: block;
height: 70px;
line-height: 70px;
width: 135px;
color: black;
text-align: center;
/*margin: auto 0;*/
font-weight: bold;
font-size: 15px;
position: absolute;
bottom: 14px;
}
li, a {
width: 135px;
height: 100px;
display: inline-block;
}
EDIT:
I want to note that span element has value bottom: 14px. THere is also animate effect on this span. when page loads span has value bottom: -70px (container has overlfow: hidden,s o this span is not seen) and then it appears (using .animate) and goes to bottom: 14px. So the sollution should consider this.
I cannot get this animate effect working in jsfiddle (http://jsfiddle.net/pr5cL/), but it works on my page that is locally created.
$("ul li:not(.img_active)").mouseenter(function() {
$(this).find("span").css("bottom","-55px");
$(this).find("span").animate({bottom:15},500);
}).mouseleave(function(){
$(this).find("span").animate({bottom:-70},500);
});
Here is link: http://www.sheerdigitaltest.net/janus/
Something like this maybe?
span {
display: inline-block;
line-height:1.25;
vertical-align:middle;
width: 135px;
color: black;
text-align: center;
font-weight: bold;
font-size: 15px;
}
a {
background-color: rgba(216, 25, 11, 0.75);
height: 70px;
line-height: 70px;
font-size:0;
overflow:hidden;
}
li, a {
width: 135px;
display: inline-block;
vertical-align:top;
}
span {
-webkit-animation: slidein 2s ; /* Safari 4+ */
-moz-animation: slidein 2s ; /* Fx 5+ */
-o-animation: slidein 2s ; /* Opera 12+ */
animation: slidein 2s ; /* IE 10+ */
}
#-webkit-keyframes slidein {
0% { margin-top: 70px; }
100% { margin-top: 0; }
}
#-moz-keyframes slidein {
0% { margin-top: 70px; }
100% { margin-top: 0; }
}
#-o-keyframes slidein {
0% { margin-top: 70px; }
100% { margin-top: 0; }
}
#keyframes slidein {
0% { margin-top: 70px; }
100% { margin-top: 0; }
}
Jsfiddle
No IE7 or earlier support. Animation support as per comments.