68.纯 CSS 创作一本色卡

原文地址:https://segmentfault.com/a/1190000015456554

感想:复习下 transform-origin: 位置;

HTML code:

<div class="cards">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>

CSS code:

html, body {
margin:;
padding:;
}
/* 设置body子元素水平垂直居中*/
body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: lightgray;
}
/* 重定义盒模型 */
.cards,
.cards > * {
/* width、height包括边框、内边距、内容区 */
box-sizing: border-box;
}
/* 设置容器样式 */
.cards {
position: relative;
font-size: 12px;
width: 20em;
height: 20em;
/* border: 1px solid blue; */
}
/* 画出色卡 */
.cards span{
width: 10em;
height: 3em;
border: 0.2em solid dimgray;
border-radius: 0.3em 0.8em 0.8em 0.3em;
/* 用 HSL 色彩模式为色卡上色 */
background-color: hsl(calc(360 / 8 * var(--n)), 80%, 70%);
position: absolute;
top: calc(50% - 3em / 2);
/* 定义动画效果,transform-origin定点绕其旋转 */
transform-origin: right;
animation: rotating 3s linear infinite;
animation-delay: calc((var(--n) - 8) * 0.15s);
}
@keyframes rotating {
0%, 35% {
transform: rotate(0deg);
} 90%, 100% {
transform: rotate(360deg);
}
}
/* 用伪元素画出色卡的标签 */
.cards span::before{
content:'';
width: 35%;
height: 100%;
border-left: 0.2em solid silver;
border-radius: 0 0.6em 0.6em 0;
background-color: white;
position: absolute;
right:;
}
.cards span::after {
content: '';
width: 0.4em;
height: 2em;
background-color: silver;
position: absolute;
left: 6.5em;
top: 0.1em;
box-shadow: 0.7em 0 0 -0.1em silver;
}
/* 为色卡设置变量 */
.cards span:nth-child(1) {
--n:;
}
.cards span:nth-child(2) {
--n:;
}
.cards span:nth-child(3) {
--n:;
}
.cards span:nth-child(4) {
--n:;
}
.cards span:nth-child(5) {
--n:;
}
.cards span:nth-child(6) {
--n:;
}
.cards span:nth-child(7) {
--n:;
}
.cards span:nth-child(8) {
--n:;
}
上一篇:杭电oj 1016 Prime Ring Problem


下一篇:【模板】HDU 1541 树状数组