【发布时间】:2022-01-21 18:09:43
【问题描述】:
我有一个小问题...当我使用 @keyframes 更改文本的外观时,我不知道如何调整 :hover letter-spacing 属性...更具体:hover 改变了我的h1 的外观如下:字体大小、位置、字母间距等。字母间距默认为 0rem,但当我将鼠标悬停在文本上时,它变为 1rem。效果很好,但是我添加了一个动画,它改变了 h1 的位置,字体大小,从 font-size: 12.5rem;字体大小:5rem;问题是当我悬停时我不知道如何更改字母间距。当它的 font-size 为 12.5rem 时;它看起来不错,但是当动画完成时,字体大小为 5rem,当我将鼠标悬停在具有 1rem 字母间距的动画上时,它看起来很糟糕。我需要一些帮助...请,因为您可以看到它的位置和字体大小发生了变化,悬停保持为 1 rem,当它具有 font-size12.5rem 时,我想将悬停字母间距从 1rem 更改为0.2rem idk 当我将鼠标悬停在它上面时,它的字体大小为 5rem ......我希望你明白我在说什么,顺便说一句,如果我犯了任何语法错误,请随时纠正我,我不是本地人演讲者,有时我的英语很困难,因此我需要知道我什么时候错了。谢谢顺便说一句。
body{
margin: 0;
padding: 0;
font-family: "Montserrat", sans-serif;
background: #1d2026;
box-sizing: border-box;
}
.dark-mode {
background: red;
transition: 1s;
}
/* Aspectul lui .Welcome*/
/*aspect of .welcome*/
.Welcome h1{
user-select: none;
font-size: 12.5rem;
letter-spacing: 0rem;
position: absolute;
margin: 0;
top: 40%;
left: 51%;
transform: translate(-50%, -50%);
text-align: center;
background: -webkit-linear-gradient(320deg,rgb(100, 38, 38), rgba(84, 0, 153, 0.39));
-webkit-background-clip: text;
background-clip: border;
-webkit-text-fill-color: transparent;
transition: 0.7s;
white-space: nowrap;
overflow-x: auto;
}
/* CSS-ul pentru animatie*/
/*the css for changePose, name duration etc*/
.Welcome h1{
animation-name: changePose;
animation-duration: 1s;
animation-delay: 6s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
/*Animatia de la hover si background-ul oferit*/
/*the hover animation which changes the size and letter-spacing*/
.Welcome h1:hover {
font-size: 13.5rem;
position: absolute;
letter-spacing: 1rem;
top: 40%;
left: 51%;
margin: 0;
background-size: cover;
transform: translate(-50%, -50%);
background: src('https://f.vividscreen.info/soft/7e879fb5d5b73ef41cffd9032e9ad55e/Red-Sky-1920x1200.jpg');/*ignore this background*/
-webkit-text-fill-color: transparent;
background-clip: border-box;
-webkit-background-clip: text;
}
/*Keyframurile de la animatia de tranzitie din mjloc
catre top*/
/* the keyframes to change that apearance of h1, from 12.5rem to 5rem*/
@keyframes changePose {
from {
position: absolute;
}
to {
position: absolute;
font-size:5rem;
align-items: center;
top: 8%;
}
}
/*Animatia efectului "ellipsis" (cele 3 puncte) loading*/
/*ellipsis animation*/
.Welcome h1::after {
overflow: hidden;
display: inline-block;
vertical-align: bottom;
-webkit-animation-timing-function: steps(4, end);
animation-timing-function: steps(4, end);
-webkit-animation: ellipsis;
animation: ellipsis;
animation-duration:1s;
animation-iteration-count: 4;
animation-delay: 1s;
content: "\2026"; /*codul ascii pentru "..."*/
width: 0px;
}
@keyframes ellipsis {
to{
width: 12.5rem;
}
}
@-webkit-keyframes ellipsis {
to {
width: 12.5rem;
}
}
.btn{
user-select: none;
font-size: 2rem;
color: #29313f;
display: inline-flex;
background: transparent;
align-items: center;
justify-content: center;
border-radius: 5.5%;
border: none;
text-decoration: none;
margin-top: 28%;
margin-left: 47%;
}
.btn:hover{
color: #303949;
text-decoration: none;
background: transparent;
align-items: center;
}
/*Adaptarea ecranului la dfierite dimensiuni*/
/*Addaption the diffrent screen resolutin*/
@media only screen and (max-width: 800px) {
.Welcome h1{
font-size: 5rem;
letter-spacing: 0;
}
.Welcome h1:hover{
font-size: 6rem;
letter-spacing: 0.4rem;
}
@keyframes changePose {
from{
font-size: 5rem;
transition: 0.7s;
}
to{
font-size: 3rem;
top: 7%;
}
}
@keyframes ellipsis {
to{
width: 5rem;
}
}
@-webkit-keyframes ellipsis {
to {
width: 5rem;
}
}
.btn{
font-size: 2rem;
margin-top: 50%;
margin-left: 44%;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>welcome</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<header>
/*<nav>
<img src="" class="logoTemp">
</nav>*/
</header>
<div class="Welcome"><h1>welcome</h1></div>
<div>
<button class =btn onclick="myFunction()">Epic mode</button>
</div>
<script>
function myFunction() {
var element = document.body;
element.classList.toggle("dark-mode");
}
</script>
</body>
</html>
【问题讨论】:
-
我认为您过度解释了一点,以至于我对所需的输出有点困惑。你能用一句话简单地解释一下主要问题是什么,你想要什么?
-
是的,抱歉,文本大小为 12.5 rem,当我将鼠标悬停在它上面时,它的字母间距从 0rem 更改为 1 rem。当字体大小为 5rem 时,我想将鼠标悬停在上面并将其字母间距从 0rem 更改为 0.2rem
标签: html css hover css-animations letter-spacing