css php 源代码,如何使用纯CSS实现一块乐高积木(附源码)

news/2024/7/8 10:16:43

本篇文章给大家带来的内容是关于php在web服务器上的运行模式详解,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

效果预览

3af2190581fce04827c9efbc6a8f2fbe.png

源代码下载

https://github.com/comehope/front-end-daily-challenges

代码解读

定义 dom,容器中包含一组 3 个面:

居中显示:body {

margin: 0;

height: 100vh;

display: flex;

align-items: center;

justify-content: center;

background: radial-gradient(circle at center, white, skyblue);

}

定义容器尺寸:.brick {

width: 40em;

height: 30em;

font-size: 10px;

}

画出积木的正面:.brick {

position: relative;

}

.sides .front {

position: absolute;

width: 9em;

height: 6.8em;

background-color: #237fbd;

top: 19em;

left: 7em;

}

画出积木的右面:.sides > * {

position: absolute;

background-color: #237fbd;

}

.sides .right {

width: 18em;

height: 6.8em;

filter: brightness(0.8);

top: 19em;

left: calc(7em + 9em);

}

画出积木的顶面:.sides .top {

width: 18em;

height: 10.4em;

filter: brightness(1.2);

top: calc(19em - 10.4em);

left: calc(7em + 9em);

}

把以上 3 个面组合成立方体:.sides .front {

transform-origin: right;

transform: skewY(30deg);

}

.sides .right {

transform-origin: left;

transform: skewY(-30deg);

}

.sides .top {

transform-origin: left bottom;

transform: rotate(-60deg) skewY(30deg);

}

接下来画积木的凸粒。

在 dom 中增加 8 个凸粒元素:

定义变量:.studs span:nth-child(1) {

--n: 1;

}

.studs span:nth-child(3) {

--n: 3;

}

.studs span:nth-child(5) {

--n: 5;

}

.studs span:nth-child(7) {

--n: 7;

}

.studs span:nth-child(2) {

--n: 2;

}

.studs span:nth-child(4) {

--n: 4;

}

.studs span:nth-child(6) {

--n: 6;

}

.studs span:nth-child(8) {

--n: 8;

}

画出左侧的凸粒:.studs span:nth-child(odd) {

top: calc(4.6em + (var(--n) - 1) / 2 * 2.6em);

left: calc(23.3em - (var(--n) - 1) / 2 * 4.6em);

}

画出右侧的凸粒:.studs span:nth-child(even) {

top: calc(6.9em + (var(--n) - 2) / 2 * 2.6em);

left: calc(27.9em - (var(--n) - 2) / 2 * 4.6em);

}

最后,画出凸粒的顶面:.studs span::before {

content: '';

position: absolute;

width: inherit;

height: 2em;

background-color: #4cb7ff;

border-radius: 50%;

}


http://www.niftyadmin.cn/n/4002397.html

相关文章

在linux机器上面安装anaconda和相关软件

直接安装anaconda参考这里,主要两条命令: wget https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh bash Anaconda3-5.0.1-Linux-x86_64.sh 然后按照anaconda 的流程: conda create -n tensorflow source activate tensorfl…

js中split,splice,slice方法之间的差异。

首先我们先来林格斯双击翻译一下: split   劈开, 使分裂; splice   接合; 使结合; slice   切成薄片, 切; 我先是这么区分的:这三个方法最后一个字母是t的是字符串方法,是e的则是数组方法&#xff08…

php$paty,CodeIgniter辅助之第三方类库third_party用法分析

本文实例分析了CodeIgniter辅助之第三方类库third_party用法。分享给大家供大家参考,具体如下:third_party用来存放系统中引入的第三方类库,类库通常提供的功能比较丰富,相应的学习成本也要高些,系统中能用到功能有限&…

小作文line chart

1.分类 2.具体描述 3.变化比较 4.极点,交叉点描写 单词 增长:increase, rise, go up, grow, be on the rise, climb 明显增长:soar(高飞 n,vi ), skyrocket(飞涨 n, vi) 减少:decrease, drop, fall, decline, be on the fall. 明显减少:plummet(骤然下跌 n, vi), sudden ab…

Android11.0 导航栏添加图标截屏

需求: 导航栏添加截屏和电源键图标,控制截屏和用于设备重启关机功能。设置中添加延时截屏和控制截屏图标显示开关。 1. 导航栏添加图标 1.1 添加布局文件和图标icon 在layout目录下添加nav_power.xml和screenshot.xml文件 frameworks/base/packages…

雅思词汇 词根+联系 记忆法 单词例句-2

Regional accent. Be secure from interruption. Preserve one’s eyesight. They are cheap because they arereject. They sought(seek) in vain for somewhere to shelter. Here’s a hat that looks like acrown. Before going to bed, pleasereview the day’s clas…

mysql截取字符串去重,mysql 截取字符串 去重 拼接

1:字符串截取LEFT(guid_,LENGTH(guid_) - 5)//1001-1002-1003 截取为 1001-10022:判断是否存在某字符串中IN(1001,1002,1003)// where id in(xxxx) 可以用查询的某个字段直接 where id in (select id from xxxx)3:根据某个字段去重复在查询结…

新概念英语第二册 阅读

Lesson 1 A private conversation 私人谈话 Last week I went to the theatre. I had a very good seat. The play was very interesting. I did not enjoy it. A young man and a young woman were sitting behind me. They were talking loudly. I got very angry. I coul…