<html>
<head>
<title>vn</title>
<style>
.box { width: 300px height: 300px background-color: red margin: 10px 0 }
#animation-1:target {
animation: rotate 1000ms linear both
}
#animation-2:target {
animation: translate 1000ms linear both
}
#animation-3:target {
animation: scale 1000ms linear both
}
@keyframes rotate {
0% { transform: rotate(0deg) }
100% { transform: rotate(360deg) }
}
@keyframes translate {
0% { transform: translate(-100%, 0) }
100% { transform: translate(0, 0) }
}
@keyframes scale {
0% { transform: scale(2) }
100% { transform: scale(1) }
}
</style>
</head>
<body>
<p>
<a href='#animation-1'>
点击后触发动画1
</a>
</p>
<p>
<a href='#animation-2'>
点击后触发动画2
</a>
</p>
<p>
<a href='#animation-3'>
点击后触发动画3
</a>
</p>
<div class="box" id="animation-1"></div>
<div class="box" id="animation-2"></div>
<div class="box" id="animation-3"></div>
</body>
</html>
不知道你是否知道target选择器的具体意义,简单的来说如下:
// div:target 的意思是锚点在目标上的时候// 看我最上面的例子,有三个链接,只有点击过以后才会触发动画。然后看看地址的变化
// 如果你想要同时全部显示,就把:target删除
额,看错了,其实你不用这么麻烦,一开始默认用33%不用判断,然后max-width: 600px最后max-width: 300px就解决了。
反正优先级相同的情况下,后面的覆盖前面的,按这个原理就很容易理解了。