首页 / 知识
HTML与CSS中的3D转换模块
2023-04-11 15:16:00
文中的img标签全部变成了macdown格式
一.什么是2D和3D
1.什么是2D和3D
2D就是一个平面,只有宽度和高度,没有厚度
3D就是一个立体,有宽度和高度,还有厚度
默认情况下所有的元素都是呈2D展现的
2.如何让某个元素呈3D展现
和透视一样,想看到某个元素的3d效果,只需要给他的父元素添加一个transform-style属性,然后设置为preserve-3d即可
3.transform-style的取值:
flat:默认取值,二维的;
preserve-3d:3D效果;
<htmllang="en"><head><metacharset="UTF-8"><title>106-3D转换模块</title><style>
*{margin:0;padding:0;}
.father{width:200px;height:200px;
background-color:red;border:1pxsolid#000;margin:100pxauto;
perspective:500px;transform-style:preserve-3d;
transform:rotateY(0deg);
}.son{width:100px;height:100px;background-color:blue;border:1pxsolid#000;margin:0auto;margin-top:50px;transform:rotateY(45deg);}</style></head><body><pclass="father"><pclass="son"></p></p></body></html>
二.正方体(有瑕疵,页面文字显示有问题)
<htmllang="en"><head><metacharset="UTF-8"><title>107-3D转换模块-正方体</title><style>*{margin:0;padding:0;}ul{width:200px;height:200px;border:1pxsolid#000;box-sizing:border-box;margin:100pxauto;position:relative;transform:rotateY(0deg)rotateX(0deg);transform-style:preserve-3d;}ulli{list-style:none;width:200px;height:200px;font-size:60px;text-align:center;line-height:200px;position:absolute;left:0;top:0;}ulli:nth-child(1){background-color:red;transform:translateX(-100px)rotateY(90deg);}ulli:nth-child(2){background-color:green;transform:translateX(100px)rotateY(90deg);}ulli:nth-child(3){background-color:blue;transform:translateY(-100px)rotateX(90deg);}ulli:nth-child(4){background-color:yellow;transform:translateY(100px)rotateX(90deg);}ulli:nth-child(5){background-color:purple;transform:translateZ(-100px);}ulli:nth-child(6){background-color:pink;transform:translateZ(100px);}</style></head><body><ul><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li></ul></body></html>
1.webp
正方体(有瑕疵,仅供了解)
三.正方体(终极方案)
旋转90度后,坐标系也跟着旋转了90度,故应该沿着z轴移动;
立体效果攻略:先旋转一定的度数,再沿z轴平移
<htmllang="en"><head><metacharset="UTF-8"><title>108-3D转换模块-正方体终极</title><style>*{margin:0;padding:0;}ul{width:200px;height:200px;border:1pxsolid#000;box-sizing:border-box;margin:100pxauto;position:relative;transform:rotateY(0deg)rotateX(0deg);transform-style:preserve-3d;}ulli{list-style:none;width:200px;height:200px;font-size:60px;text-align:center;line-height:200px;position:absolute;left:0;top:0;}
ulli:nth-child(1){background-color:red;transform:rotateX(90deg)translateZ(100px);}
ulli:nth-child(2){background-color:green;transform:rotateX(180deg)translateZ(100px);}ulli:nth-child(3){background-color:blue;transform:rotateX(270deg)translateZ(100px);}ulli:nth-child(4){background-color:yellow;transform:rotateX(360deg)translateZ(100px);}ulli:nth-child(5){background-color:purple;transform:translateX(-100px)rotateY(90deg);}ulli:nth-child(6){background-color:pink;transform:translateX(100px)rotateY(90deg);}</style></head><body><ul><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li></ul></body></html>
本文转载自中文网 |
最新内容
相关内容
文本处理用c还是用python
文本处理用c还是用python,位置,培训,包装,对比,字符串,函数,文本,语言,字符,效率,文本处理python与c的对比:如下c++语言:C++语言实现C++中没有python3如何引入模块?
python3如何引入模块?,系统,位置,培训,标准,模块,方法,成员,路径,下面,别名,使用Python进行编程时,有些功能没必须自己实现,可以借助Python现有python如何调用另一个文件夹中的内
python如何调用另一个文件夹中的内容?,系统,培训,文件,模块,内容,路径,函数,所在,前缀,语句,python中调用另外一个文件夹中的内容:1、同一文件Python怎么取出列表中的相邻元素?
Python怎么取出列表中的相邻元素?,代码,异常,培训,元素,指针,序列,对象,表示,语句,函数,1、python的迭代器。iter()能把一个序列生成为一个和python怎么判断文档是否有指定后缀
python怎么判断文档是否有指定后缀?,培训,后缀,文档,文件夹,路径,以上,文件,方法,更多,内容,python判断文档是否有指定后缀的方法:importosYou如何在python代码中指定保存的文件
如何在python代码中指定保存的文件格式,代码,培训,文件格式,格式,二进制文件,文件,后缀,以上,方法,更多,python指定保存文件格式的方法:1、保Python如何复制文件中的内容
Python如何复制文件中的内容,盘中,数据,培训,文件,内容,方法,文件夹,路径,源文件,文件名,python复制文件中内容的方法:1、使用shutil.copyfilepython中的open函数如何编码?
python中的open函数如何编码?,数据,系统,可取,培训,文件,参数,函数,时候,表示,模式,python中的open函数可以通过在打开文件时添加encoding参python如何获取打开文件的行数?
python如何获取打开文件的行数?,数据,培训,文件,方法,列表,下标,字符串,序列,函数,长度,python获取打开文件行数的方法:1、文件较小时可以使用Python中怎么新建文件夹
Python中怎么新建文件夹,代码,工作,培训,文件夹,路径,函数,操作系统,示例,文件名,以上,python中如何新建文件夹的方法:可以使用os包的mkdir函怎么查看python模块在什么位置
怎么查看python模块在什么位置,位置,代码,培训,模块,路径,下面,以上,文件,方法,更多,查看python模块在什么位置的方法:若要获取模块的文件名为python中的int是什么意思?
python中的int是什么意思?,数字,数据,培训,字符串,参数,语法,实例,以下,方法,函数,python中的int()函数用于将一个字符串或数字转换为整型。