【发布时间】:2023-03-17 18:47:01
【问题描述】:
<!DOCTYPE html>
<html>
<head>
<style>
@import url(https://fonts.googleapis.com/css?family=Open+Sans:600);
body {
font-family: 'Open Sans', 'sans-serif';
color: #cecece;
background: #222;
overflow: hidden;
}
.item-1,
.item-2{
position: absolute;
display: block;
top: 2em;
width: 60%;
font-size: 2em;
animation-duration: 20s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
}
.item-1{
animation-name: anim-1;
}
.item-2{
animation-name: anim-2;
}
@keyframes anim-1 {
0%, 8.3% { left: -100%; opacity: 0; }
8.3%,25% { left: 25%; opacity: 1; }
33.33%, 100% { left: 110%; opacity: 0; }
}
@keyframes anim-2 {
0%, 8.3% { left: -100%; opacity: 0; }
8.3%,25% { left: 25%; opacity: 1; }
33.33%, 100% { left: 110%; opacity: 0; }
}
</style>
</head>
{% for person in persons %}
<p class="item-1">
Person Name: {{ persons.awards_type }}
<br/>
<br/>
Person ID: {{ persons.awards_nomination }}
<br/>
Job: {{ persons.reason }}
</p>
{% endfor %}
</html>
我是 CSS 和 HTML 的新手,想知道是否可以在同一类的不同对象上使用相同的 CSS 动画。 persons 是类 Person 中包含人员信息的对象列表。
我想将persons 列表中的每个对象显示为动画。由于列表中的元素数量可能会发生变化,我想知道如何实现这一点。
我正在使用 django 将persons 列表发送到 HTML 页面。
<!DOCTYPE html>
<html>
<head>
<style>
@import url(https://fonts.googleapis.com/css?family=Open+Sans:600);
body {
font-family: 'Open Sans', 'sans-serif';
color: #cecece;
background: #222;
overflow: hidden;
}
.item-1{
position: absolute;
display: block;
top: 2em;
width: 60%;
font-size: 2em;
animation-duration: 20s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
}
.item-1{
animation-name: anim-1;
}
@keyframes anim-1 {
0%, 8.3% { left: -100%; opacity: 0; }
8.3%,25% { left: 25%; opacity: 1; }
33.33%, 100% { left: 110%; opacity: 0; }
}
</style>
</head>
{% for person in persons %}
<p class="item-1">
Person Name: {{ person.person_name }}
<br/>
<br/>
Person ID: {{ person.person_id }}
<br/>
Job: {{ person.occupation }}
</p>
{% endfor %}
</html>
【问题讨论】:
-
请创建一个有效的 sn-p - 您在此处的编辑工具栏中有 sn-p 按钮