gpt4 book ai didi

css - 如何让这个设计响应?

转载 作者:太空宇宙 更新时间:2023-11-04 00:42:05 25 4
gpt4 key购买 nike

我曾尝试使用 CSS 关键帧制作动画,但设计有问题。我怎样才能在不编写媒体查询的情况下使其响应,因为它只是一个简单的动画代码?

div {
font-family: "Comic Sans MS", sans-serif;
margin-left: 200px;
margin-top: 200px;
}

span {
color: white;
font-size: 35px;
padding: 14px 25px;
margin: 5px;
border-radius: 10px;
display: inline-block;
animation: move 0.8s infinite linear;
}

@keyframes move {
0% {
transform: translateY(0px);
opacity: 1.0;
}
50% {
transform: translateY(-50px);
opacity: 0.5;
}
100% {
transform: translateY(0px);
opacity: 1.0;
}
}

span:nth-child(1) {
animation-delay: 0.1s;
background-color: red;
box-shadow: 5px 5px 0 black;
}

span:nth-child(2) {
animation-delay: 0.2s;
background-color: blue;
box-shadow: 5px 5px 0 black;
}

span:nth-child(3) {
animation-delay: 0.3s;
background-color: green;
box-shadow: 5px 5px 0 black;
}

span:nth-child(4) {
animation-delay: 0.4s;
background-color: orangered;
box-shadow: 5px 5px 0 black;
}

span:nth-child(5) {
animation-delay: 0.5s;
background-color: springgreen;
box-shadow: 5px 5px 0 black;
}

span:nth-child(6) {
animation-delay: 0.6s;
background-color: blueviolet;
box-shadow: 5px 5px 0 black;
}

span:nth-child(7) {
animation-delay: 0.7s;
background-color: purple;
box-shadow: 5px 5px 0 black;
}
<div>
<span>W</span>
<span>E</span>
<span>L</span>
<span>C</span>
<span>O</span>
<span>M</span>
<span>E</span>
</div>

最佳答案

在不使用媒体查询的情况下,您的操作将受到限制,但在本例中,我删除了您设置的 margin-left 值并使用百分比代替,并使包含 div 百分比宽度。我还让父 div 成为一个 flex 容器——这将确保在较小的屏幕上更难包装。

然后我使用 vw 单位作为字体大小,因此它会随窗口宽度缩放。盒子上的填充也需要设置为百分比。你可以在这里玩:

https://jsfiddle.net/disinfor/s5hkyr2f/3/

div {
font-family: "Comic Sans MS", sans-serif;
margin: 200px auto 0;
width: 90%;
display: flex;
justify-content: center;
}

span {
color: white;
font-size: 4vw;
padding: 2% 3%;
margin: 5px;
border-radius: 10px;
display: inline-block;
animation: move 0.8s infinite linear;
}

@keyframes move {
0% {
transform: translateY(0px);
opacity: 1.0;
}
50% {
transform: translateY(-50px);
opacity: 0.5;
}
100% {
transform: translateY(0px);
opacity: 1.0;
}
}

span:nth-child(1) {
animation-delay: 0.1s;
background-color: red;
box-shadow: 5px 5px 0 black;
}

span:nth-child(2) {
animation-delay: 0.2s;
background-color: blue;
box-shadow: 5px 5px 0 black;
}

span:nth-child(3) {
animation-delay: 0.3s;
background-color: green;
box-shadow: 5px 5px 0 black;
}

span:nth-child(4) {
animation-delay: 0.4s;
background-color: orangered;
box-shadow: 5px 5px 0 black;
}

span:nth-child(5) {
animation-delay: 0.5s;
background-color: springgreen;
box-shadow: 5px 5px 0 black;
}

span:nth-child(6) {
animation-delay: 0.6s;
background-color: blueviolet;
box-shadow: 5px 5px 0 black;
}

span:nth-child(7) {
animation-delay: 0.7s;
background-color: purple;
box-shadow: 5px 5px 0 black;
}
<div>
<span>W</span>
<span>E</span>
<span>L</span>
<span>C</span>
<span>O</span>
<span>M</span>
<span>E</span>
</div>

关于css - 如何让这个设计响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58098398/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com