【问题标题】:How to make this design responsive?如何使这个设计响应?
【发布时间】:2020-01-25 15:30:38
【问题描述】:

我曾尝试使用 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>

【问题讨论】:

  • 这与 css 动画无关。这是关于这个词根本不适合屏幕的事实。这将是您想要的结果?你想让字母变小以适应屏幕吗?
  • 我想要整个 Ui,包括 div
  • 好吧,您的评论使它更加不清楚:)。你想在不使用媒体查询的情况下做到这一点吗?所以你在容器上设置margin-left:200px,在跨度上设置font-size: 35px;。 (除其他外)你想保持这些价值观,但也让它适合屏幕?这是不可能的。
  • 真的吗?
  • 不,我只是在问。呵呵

标签: css animation responsive keyframe


【解决方案1】:

如果不使用媒体查询,您只能做一些事情,但在此示例中,我已删除您设置的 margin-left 值并改用百分比,并将包含的 div 设置为百分比宽度。我还让父 div 成为一个弹性容器——这将确保在较小的屏幕上更难包裹。

然后我使用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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多