ToB企服应用市场:ToB评测及商务社交产业平台

标题: 前端练习小项目——方向感应名片 [打印本页]

作者: 北冰洋以北    时间: 2024-7-16 04:25
标题: 前端练习小项目——方向感应名片
        媒介:在学习完HTML和CSS之后,我们就可以开始做一些小项目了,本篇文章所讲的小项目为——方向感应名片

   

  ✨✨✨这里是秋刀鱼不做梦的BLOG
  ✨✨✨想要相识更多内容可以访问我的主页秋刀鱼不做梦-CSDN博客
  在开始学习之前,先让我们看一下最终效果:

        那么我们怎样去实现这样的小案例呢?在下文中我们对每一段告急的代码都举行相识释,读者可以根据注释对代码举行明白。

1.HTML代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>fish</title> <!-- 设置页面标题为fish -->
  8.     <link rel="stylesheet" href="./test.css"> <!-- 引入外部CSS样式表 -->
  9. </head>
  10. <body>
  11.     <div class="shell"> <!-- 外层容器 -->
  12.         <div class="box"> <!-- 盒子容器 -->
  13.             <div class="images"> <!-- 图片容器 -->
  14.                 <img src="./item1.jpg"> <!-- 显示item1.jpg图片 -->
  15.             </div>
  16.             <div class="content"> <!-- 内容容器 -->
  17.                 <h2>ZeenChin</h2> <!-- 标题为ZeenChin -->
  18.                 <p>The style in the painting integrates temptation, fantasy and strangeness
  19.                 </p> <!-- 段落内容描述绘画风格 -->
  20.             </div>
  21.         </div>
  22.         <!-- 后续box结构与前面类似,每个box包含图片和内容 -->
  23.         <div class="box">
  24.             <div class="images">
  25.                 <img src="./item2.jpg">
  26.             </div>
  27.             <div class="content">
  28.                 <h2>ZeenChin</h2>
  29.                 <p>The style in the painting integrates temptation, fantasy and strangeness
  30.                 </p>
  31.             </div>
  32.         </div>
  33.         <div class="box">
  34.             <div class="images">
  35.                 <img src="./item3.jpg">
  36.             </div>
  37.             <div class="content">
  38.                 <h2>ZeenChin</h2>
  39.                 <p>The style in the painting integrates temptation, fantasy and strangeness
  40.                 </p>
  41.             </div>
  42.         </div>
  43.         <div class="box">
  44.             <div class="images">
  45.                 <img src="./item4.jpg">
  46.             </div>
  47.             <div class="content">
  48.                 <h2>ZeenChin</h2>
  49.                 <p>The style in the painting integrates temptation, fantasy and strangeness
  50.                 </p>
  51.             </div>
  52.         </div>
  53.         <div class="box">
  54.             <div class="images">
  55.                 <img src="./item5.jpg">
  56.             </div>
  57.             <div class="content">
  58.                 <h2>ZeenChin</h2>
  59.                 <p>The style in the painting integrates temptation, fantasy and strangeness
  60.                 </p>
  61.             </div>
  62.         </div>
  63.     </div>
  64. </body>
  65. </html>
复制代码
        看完上述的代码之后,我相信读者已经有了大致的内容明白了,现在在让我们简单的回顾一下上述的代码:
      其中<head>部门包罗网页标题“fish”和引入外部CSS样式表test.css。主体部门由一个外层容器<div class="shell">包裹,其中包罗多个盒子<div class="box">,每个盒子内部有图片容器<div class="images">和内容容器<div class="content">,展示了不同的图片(如item1.jpg至item5.jpg)
          ——这里读者可以先对HTML中的代码举行简单的编写,这里直接展示HTML代码的效果了:

这样我们就大致的将网页的骨架搭建完成了,接下来在让我们编写CSS代码来举行对其的美化。

2.CSS代码

  1. * {
  2.     margin: 0;
  3.     padding: 0;
  4. }
  5. body {
  6.     /* 将内容区域居中显示 */
  7.     display: flex;
  8.     /* 使用 Flex 布局 */
  9.     justify-content: center;
  10.     /* 水平居中 */
  11.     align-items: center;
  12.     /* 垂直居中 */
  13.     min-height: 100vh;
  14.     /* 最小高度占据整个视口 */
  15.     /* 设置背景渐变色 */
  16.     background-image: linear-gradient(to top, #fbc2eb 0%, #a6c1ee 100%);
  17. }
  18. .shell {
  19.     /* 设置相对定位,启用3D变换 */
  20.     position: relative;
  21.     min-width: 1000px;
  22.     /* 最小宽度为1000像素 */
  23.     display: flex;
  24.     /* 使用 Flex 布局 */
  25.     justify-content: center;
  26.     /* 水平居中 */
  27.     flex-wrap: wrap;
  28.     /* 换行排列子元素 */
  29.     transform-style: preserve-3d;
  30.     /* 保持3D变换 */
  31.     perspective: 900px;
  32.     /* 设置透视效果 */
  33. }
  34. .shell .box {
  35.     /* 设置相对定位和固定宽高 */
  36.     position: relative;
  37.     width: 250px;
  38.     /* 宽度250像素 */
  39.     height: 350px;
  40.     /* 高度350像素 */
  41.     transition: 0.6s;
  42.     /* 过渡效果时长 */
  43.     overflow: hidden;
  44.     /* 隐藏溢出部分 */
  45.     margin: 30px;
  46.     /* 外边距为30像素 */
  47.     transform: rotateY(0deg);
  48.     /* 默认Y轴旋转角度为0度 */
  49.     transition-delay: .1s;
  50.     /* 过渡延迟0.1秒 */
  51.     border-radius: 5px;
  52.     /* 设置圆角为5像素 */
  53.     border: #fff 5px solid;
  54.     /* 边框为白色5像素实线 */
  55. }
  56. /* 鼠标悬停在 .shell 上时 */
  57. .shell:hover .box {
  58.     transform: rotateY(20deg);
  59.     /* 所有 .box 元素绕Y轴旋转20度 */
  60. }
  61. /* 鼠标悬停在 .box 上时 */
  62. .shell .box:hover {
  63.     transform: rotateY(0deg) scale(1.25);
  64.     /* 当前 .box 元素恢复到0度旋转并放大到1.25倍 */
  65.     box-shadow: 0 25px 40px rgba(0, 0, 0, 0.7);
  66.     /* 添加阴影效果 */
  67.     z-index: 1;
  68.     /* 设置堆叠顺序为1,使其位于最顶层 */
  69. }
  70. /* 鼠标悬停在 .box 上时,其他 .box 元素的效果 */
  71. .shell .box:hover~.box {
  72.     transform: rotateY(-20deg);
  73.     /* 其他 .box 元素绕Y轴反向旋转20度 */
  74. }
  75. .shell .box .images img {
  76.     width: 100%;
  77.     /* 图片宽度100% */
  78. }
  79. .shell .box .content {
  80.     position: absolute;
  81.     /* 绝对定位 */
  82.     top: 0;
  83.     /* 顶部与父元素对齐 */
  84.     width: 90%;
  85.     /* 宽度90% */
  86.     height: 100%;
  87.     /* 高度100% */
  88.     z-index: 999;
  89.     /* 设置堆叠顺序为999,使内容层位于最顶层 */
  90.     padding: 15px;
  91.     /* 内边距为15像素 */
  92. }
  93. .shell .box .content h2 {
  94.     color: rgb(210, 140, 140);
  95.     /* 设置标题颜色 */
  96.     transition: 0.6s;
  97.     /* 过渡效果时长 */
  98.     font-size: 20px;
  99.     /* 字体大小20像素 */
  100.     transform: translateY(-100px);
  101.     /* 初始位置向上偏移100像素 */
  102. }
  103. /* 鼠标悬停在 .box 上时的标题效果 */
  104. .shell .box:hover .content h2 {
  105.     transform: translateY(-15px);
  106.     /* 标题向上偏移15像素 */
  107. }
  108. .shell .box .content p {
  109.     color: rgb(0, 0, 0);
  110.     /* 设置段落文本颜色 */
  111.     transition: 0.6s;
  112.     /* 过渡效果时长 */
  113.     font-size: 14px;
  114.     /* 字体大小14像素 */
  115.     transform: translateY(600px);
  116.     /* 初始位置向下偏移600像素 */
  117.     background-color: rgba(255, 255, 255, 0.7);
  118.     /* 设置背景颜色及透明度 */
  119. }
  120. /* 鼠标悬停在 .box 上时的段落效果 */
  121. .shell .box:hover .content p {
  122.     transform: translateY(220px);
  123.     /* 段落向下偏移220像素 */
  124. }
复制代码
        注:上边的代码中我们将每一行代码的解说都附在了代码的上边,希望读者可以跟随着代码中的注释来明白每行代码的用意。
这里我们在简单的举行解释一下:

             ——最终我们将代码运行尽可以得到最终效果啦!(如图)



以上就是本篇文章的全部内容了~~~


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4