I have a problem with scaling in CSS. div.container has transform: scale(0.1), so because of normal font size, h1 in this element has transform: scale(10).
After hover, div.container has transform: scale(0.5) and h1 transform: scale(2). Everything is animated (transition: all 1s ease-in-out).
However, animation of h1 isn't as fast as animation of div.container, so after hover, h1 is very big at the beginning of animation, and then quicky shrinks.
I think it's happening because of h1 should have invert easing. But what easing is invert to ease-in-out? Or is the problem elsewhere?
Note: I can't scaling only div.image. This code is only example. I have to scaling div.container.
.container, .title {
transition: all 1s ease-in-out;
}
.image {
background-image: url(https://www.w3schools.com/css/trolltunga.jpg);
background-size: 100% auto;
background-repeat: no-repeat;
height: 300px;
width: 800px;
}
.container {
transform: scale(0.1);
}
.title {
margin: 0;
text-align: center;
padding-top: 1rem;
transform: scale(10);
}
.container:hover {
transform: scale(0.5);
}
.container:hover .title {
transform: scale(2);
}
<div class="container">
<div class="image">
</div>
<h1 class="title">Title</h1>
</div>
I found out that it doesn't work with linear easing. So, problem is not in easing.
.container, .title {
transition: all 1s linear;
}
.image {
background-image: url(https://www.w3schools.com/css/trolltunga.jpg);
background-size: 100% auto;
background-repeat: no-repeat;
height: 300px;
width: 800px;
}
.container {
transform: scale(0.1);
}
.title {
margin: 0;
text-align: center;
padding-top: 1rem;
transform: scale(10);
}
.container:hover {
transform: scale(0.5);
}
.container:hover .title {
transform: scale(2);
}
<div class="container">
<div class="image">
</div>
<h1 class="title">Title</h1>
</div>
Related
I would like to make a slider a bit like this example:
https://codepen.io/zhangzor/pen/XWKxNJN?editors=1100
The squares should always show the same face and not move like a turnstile, but I can't seem to do that? When I update the rotate boxes individually, their position is reset.
Do you know how to do this with pure CSS (no Three.js or other libraries)?
Thank you and have a good day
body {
perspective: 1000px;
}
.box {
position: relative;
width: 300px;
height: 200px;
margin: 150px auto;
transform-style: preserve-3d;
animation: move 10s linear infinite;
}
.box:hover {
animation-play-state: paused;
}
#keyframes move {
0% {
transform: rotateY(0);
}
100% {
transform: rotateY(360deg);
}
}
div {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: skyblue;
}
.box div:first-child {
transform: rotateY(0) translateZ(300px);
}
.box div:nth-child(2) {
transform: rotateY(60deg) translateZ(300px);
}
.box div:nth-child(3) {
transform: rotateY(120deg) translateZ(300px);
}
.box div:nth-child(4) {
transform: rotateY(180deg) translateZ(300px);
}
.box div:nth-child(5) {
transform: rotateY(240deg) translateZ(300px);
}
.box div:last-child {
transform: rotateY(300deg) translateZ(300px);
}
<div class="box">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
Rotation of inner divs depends on .box rotation so controlling them directly becomes a mess since their X an Y axis rotates with a .box.
But You can apply alternate rotation to their inner elements, using divs as moving containers.
https://codepen.io/accwatcp-the-vuer/pen/eYRdWZz
To transfer parent pre-rotation parameter to children just put it in css-variable - then it can be used for all its children elements. That will be used in counter rotation animation styling.
Now every child have its --shift parameter and can evaluate --shift2 (shift to) final counter-rotation parameter.
Also put repeated Z coordinate for translation to variable, just for ease of use.
* {
margin: 0;
padding: 0;
}
body {
perspective: 1000px;
}
.box {
position: relative;
width: 300px;
height: 200px;
margin: 150px auto;
transform-style: preserve-3d;
animation: move 10s linear infinite;
transform-origin: center bottom;
}
.box:hover, .box:hover span {
animation-play-state: paused;
}
#keyframes move {
0% {
transform: rotateY(0);
}
100% {
transform: rotateY(360deg);
}
}
#keyframes backmove {
0% {
transform: rotateY(var(--shift));
}
100% {
transform: rotateY(var(--shift2));
}
}
div {
--shiftZ:350px;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: transparent;
transform-style: preserve-3d;
}
.box div:first-child {
--shift:0deg;
transform: rotateY(calc(var(--shift)*(-1))) translateZ(var(--shiftZ));
}
.box div:nth-child(2) {
--shift:60deg;
transform: rotateY(calc(var(--shift)*(-1))) translateZ(var(--shiftZ));
}
.box div:nth-child(3) {
--shift:120deg;
transform: rotateY(calc(var(--shift)*(-1))) translateZ(var(--shiftZ));
}
.box div:nth-child(4) {
--shift:180deg;
transform: rotateY(calc(var(--shift)*(-1))) translateZ(var(--shiftZ));
}
.box div:nth-child(5) {
--shift:240deg;
transform: rotateY(calc(var(--shift)*(-1))) translateZ(var(--shiftZ));
}
.box div:last-child {
--shift:300deg;
transform: rotateY(calc(var(--shift)*(-1))) translateZ(var(--shiftZ));
}
span{
--shift2:calc(var(--shift) - 360deg);
display:flex;
background-color: #f003;
border:1px dashed black;
min-width:100%;
min-height:100%;
animation: backmove 10s linear infinite;
justify-content:center;
align-items:center;
font-size:5rem;
}
<section class="box">
<div><span>1</span></div>
<div><span>2</span></div>
<div><span>3</span></div>
<div><span>4</span></div>
<div><span>5</span></div>
<div><span>6</span></div>
</section>
I've been trying to animate my image with almost all transform functions without success.
After googling it appeared that setting with: auto might be the cause.
But removing it from my style doesn't change anything at all. Still no animation.
Here you have my code :
html,
body {
height: 100%;
}
body {
margin: 0;
}
.logo-container {
display: flex;
height: 100%;
background-color: red;
justify-content: center;
align-items: center;
}
.logo {
width: auto;
transition: scale-me 1.5s ease-in;
animation-iteration-count: infinite;
}
#keyframes scale-me {
0% {
transform: scale(1);
}
50% {
transform: scale(1.5);
}
100% {
transform: scale(1);
}
}
<body>
<div class="logo-container">
<img src="../images/Green-Monster-8-icon-128.png" class="logo" />
</div>
</body>
What is wrong in my code ?
Thanks in advance.
You have to use animation instead of transition
html,
body {
height: 100%;
}
body {
margin: 0;
}
.logo-container {
display: flex;
height: 100%;
background-color: red;
justify-content: center;
align-items: center;
}
.logo {
width: auto;
animation: scale-me 1.5s ease-in;
animation-iteration-count: infinite;
}
#keyframes scale-me {
0% {
transform: scale(1);
}
50% {
transform: scale(1.5);
}
100% {
transform: scale(1);
}
}
<body>
<div class="logo-container">
<img src="https://via.placeholder.com/50" class="logo" />
</div>
</body>
i have a little issue with the css animation and keyframe feature...
i have a little monster with blinking eyes... the eyes should blink just 0.1s
And then i want to have a duration... and then the animation should loop.
This is my animation/keyframe:
#keyframes blinkingEyes {
0% {
transform: rotateX(0deg);
}
36% {
transform: rotateX(90deg);
}
100% {
transform: rotateX(90deg);
}
}
And this is my animation property:
animation: blinkingEyes 0.15s 1s infinite linear;
JSFIDDLE
I found a workaround with a x% between my start and end value. But nothing works for me.. i hope you could help me
You need several keyframes for this, and then make the animation run infinite times.
See:
#monster {
margin-top: 60px;
height: 93px;
width: 75px;
border-radius: 120px;
background: yellow;
/* text-align: center; */
position: relative;
}
.eye {
height: 12px;
width: 8px;
background: black;
border-radius: 10px;
margin-top: 30px;
float: left;
animation: blinkingEyes 1.5s linear infinite;
}
.eyeLeft {
margin-left: 18px;
}
.eyeRight {
margin-left: 22px;
}
.mouth {
font-weight: 900;
transform-origin: 50% 50%;
/* display: inline-block; */
width: 5px;
margin: 0 auto;
height: 20px;
/* text-align: center; */
/* left: 47%; */
position: absolute;
top: 47px;
transform: rotate(90deg);
left: 35px;
}
#keyframes blinkingEyes {
0%, 97%, 100% {
transform: rotateX(0deg);
}
98%, 99% {
transform: rotateX(90deg);
}
}
<div id="monster">
<div class="monsterBody">
<div class="eye eyeLeft">
</div>
<div class="eye eyeRight">
</div>
<div class="mouth">
)
</div>
</div>
</div>
What can I do to avoid the image blurry/flickering issue when using CSS transform? I've tried a bunch of suggestions from CSS transition effect makes image blurry / moves image 1px, in Chrome?, but cannot seem to figure it out.
I've attached the plunker code below.
https://plnkr.co/edit/kXbrxjnD0llt3u8dBujv?p=preview
index.html
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<img src="usequities_green.svg" class="sample_fixed_income">
<section class="sectors">
<div class="container index-container-responsive">
<div class="row">
<div class="sectors-icon">
<img src="usequities_green.svg" class="sectors-icon-container fixed_income">
</div>
</div>
</div>
</section> </body>
</html>
style.css
/* Styles go here */
.sectors {
background-color: #30B784;
color: white;
display: flex;
height: 680px;
align-items: center;
justify-content: center;
position: relative;
}
.sectors__section__title {
font-size: 32px;
line-height: 48px;
}
.sectors-icon .sectors-icon-container{
animation-direction: alternate;
animation-iteration-count: infinite;
animation-play-state: running;
animation-timing-function: ease-in-out;
background-color: white;
background-position: center;
background-repeat: no-repeat;
border-radius: 50%;
box-shadow: 0 10px 40px 0 rgba(23, 28, 33, 0.13), 0 31px 13px 0 rgba(23, 28, 33, 0.05);
opacity: 1;
transition: margin 0s cubic-bezier(0.2,0.6,0.3,1), opacity 0s ease;
}
#keyframes floating_fixed_income {
0% {
transform: translate(0%,0%);
}
12.5% {
transform: translate(-2%,1%);
}
25% {
transform: translate(-4%,2%);
}
50% {
transform: translate(-2%,3%);
}
62.5% {
transform: translate(0%,2%);
}
75% {
transform: translate(1%,1%);
}
100% {
transform: translate(2%,0%);
}
}
.sectors-icon-container.fixed_income {
animation-name: floating_fixed_income;
animation-duration: 5s;
height: 112px;
background-size: 112%;
width: 112px;
margin-left: 73%;
margin-top: -11%;
}
I think it's a bug. Not as neat but my recommendation is to just go with animating an absolutely positioned element for now. You can position your sectors-icon where you want it, give it relative positioning and then add the hovering animation to it's child img with absolute positioning:
#keyframes floating_fixed_income {
0% {
top: 0;
}
12.5% {
top: 20px;
}
25% {
top: 10px;
}
50% {
top: 100px;
}
62.5% {
top: 50px;
}
75% {
top: 20px;
}
100% {
top: 0;
}
}
https://plnkr.co/edit/YHIeL9vO2nQpTaoBpup3?p=preview
I'm rotating a div around a circular path with css, and I want to make it change color on hover.
See demo here: http://jsfiddle.net/gg7tnueu/1/
html,
body {
height: 100%;
margin: 0;
}
.planet {
border-radius: 50%;
border: 2px solid #1a1a1a;
position: absolute;
margin: auto;
/*top: 50%;*/
-webkit-animation: orbit 6s infinite linear;
-webkit-backface-visibility: hidden;
-webkit-transform: translateZ(0);
animation: orbit 6s infinite linear;
backface-visibility: hidden;
transform: translateZ(0);
}
.planet.code {
-webkit-transform-origin: 8.5vh 7.875vh;
transform-origin: 8.5vh 7.875vh;
}
.planet.code:hover {
background: red;
}
#-webkit-keyframes orbit {
0% {
-webkit-transform: rotate(0);
}
100% {
-webkit-transform: rotate(360deg);
}
}
#keyframes orbit {
0% {
transform: rotate(0);
}
100% {
transform: rotate(360deg);
}
}
.ring {
margin: auto;
border-radius: 50%;
border: 2px solid #1a1a1a;
position: relative;
top: 50%;
transform: translateY(-50%);
}
.ring.inner.middle {
width: 75%;
height: 75%;
}
.ring.inner.last {
width: 30%;
height: 30%;
}
#media (orientation: landscape) {
.ring.outer {
width: 75vh;
height: 75vh;
}
.planet {
width: 3.75vh;
height: 3.75vh;
}
}
#media screen and (orientation: portrait) {
.ring.outer {
width: 75vw;
height: 75vw;
}
.planet {
width: 3.75vw;
height: 3.75vw;
left: -1.875vw;
}
}
<div class="ring outer">
<div class="ring inner middle">
<div class="ring inner last">
<div class='planet code'>
</div>
</div>
</div>
</div>
The hover is detected pretty consistently in Firefox (when I add the -moz prefix...), but it's rarely detected in Chrome.
The same thing happens when I add an onclick handler.
Does anyone have any advice to make it work better?
Screenshot of issue
It seems you'll have to use javascript since, as #vals said, the :hover state is not recalculated unless the mouse is moved.