30 3D导航栏

效果演示

在这里插入图片描述

实现了一个导航栏,其中包含了五个图标,每个图标都有一个悬浮的文字标签,当鼠标悬停在图标上时,文字标签会旋转并向上移动,同时底部会出现一个阴影效果。整个导航栏的背景颜色为浅灰色。

Code

<ul>
    <li>
        <span class="iconfont icon-QQ"></span>
        <span class="iconfont icon-QQ"></span>
    </li>
    <li>
        <span class="iconfont icon-weixin"></span>
        <span class="iconfont icon-weixin"></span>
    </li>
    <li>
        <span class="iconfont icon-douyin"></span>
        <span class="iconfont icon-douyin"></span>
    </li>
    <li>
        <span class="iconfont icon-xinlangweibo"></span>
        <span class="iconfont icon-xinlangweibo"></span>
    </li>
    <li>
        <span class="iconfont icon-shouji"></span>
        <span class="iconfont icon-shouji"></span>
    </li>
</ul>
@font-face {
   
    font-family: "iconfont";
    /* Project id 4096975 */
    src: url('//at.alicdn.com/t/c/font_4096975_pswyqyk8tdo.woff2?t=1685517797434') format('woff2'),
        url('//at.alicdn.com/t/c/font_4096975_pswyqyk8tdo.woff?t=1685517797434') format('woff'),
        url('//at.alicdn.com/t/c/font_4096975_pswyqyk8tdo.ttf?t=1685517797434') format('truetype');
}

.iconfont {
   
    font-family: "iconfont" !important;
    font-size: 16px;
    font-style: normal;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.icon-xinlangweibo:before {
   
    content: "\e600";
}

.icon-shouji:before {
   
    content: "\e601";
}

.icon-weixin:before {
   
    content: "\e602";
}

.icon-jingdong:before {
   
    content: "\e812";
}

.icon-taobao:before {
   
    content: "\e755";
}

.icon-shoujitaobao:before {
   
    content: "\e786";
}

.icon-alipay:before {
   
    content: "\e618";
}

.icon-QQ:before {
   
    content: "\e882";
}

.icon-douyin:before {
   
    content: "\e8db";
}

.icon-pinduoduo:before {
   
    content: "\e8df";
}

/* 1.去除默认样式 设置底色 */
* {
   
    margin: 0;
    padding: 0;
}

body {
   
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #e8e8e8;
}

/* 2.准备导航的基本样式 */
ul {
   
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    list-style: none;
}

/* 3.1 准备导航里面图标的基本样式 */
ul li {
   
    position: relative;
    margin: 0 2px;
    width: 40px;
    height: 40px;
}

ul li span {
   
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    line-height: 40px;
    font-size: 16px;
    background: #fff;
    color: #262626;
    transform-origin: top;
    text-align: center;
    cursor: pointer;
}

ul li span:nth-child(2) {
   
    background: #3b5999;
    color: #fff;
    transform-origin: bottom;
    transform: rotateX(90deg) translateY(50%);
}


/* 3.1.1 鼠标悬停 旋转 上移 */
ul li span {
   
    transition: all 0.5s;
}

ul li span:nth-child(1) {
   
    transform-origin: top;
}

ul li:hover span:nth-child(1) {
   
    transform: rotateX(90deg) translateY(-50%);
}

ul li:hover span:nth-child(2) {
   
    transform: rotateX(0deg) translateY(0);
}

ul li:hover {
   
    transform: translateY(-10px);
}

/* 3.2 导航下面图标的底色 */
ul li:nth-child(1) span:nth-child(2) {
   
    background: #3b5999;
}

ul li:nth-child(2) span:nth-child(2) {
   
    background: #05e07a;
}

ul li:nth-child(3) span:nth-child(2) {
   
    background: #dd4b39;
}

ul li:nth-child(4) span:nth-child(2) {
   
    background: #b50088;
}

ul li:nth-child(5) span:nth-child(2) {
   
    background: #d9e440;
}

*/

/* 4. 添加底部的阴影效果 */
ul li::before {
   
    content: "";
    position: absolute;
    left: 0;
    bottom: -10px;
    width: 40px;
    height: 8px;
    background: #000;
    border-radius: 50%;
    transition: .5s;
    opacity: 0;
    filter: blur(2px);
    transform: scale(0.8);

}

ul li:hover::before {
   
    transition-delay: .5s;
    opacity: .2;
    transform: scale(1);
}

实现思路拆分

@font-face {
   
  font-family: "iconfont";
  /* Project id 4096975 */
  src: url('//at.alicdn.com/t/c/font_4096975_pswyqyk8tdo.woff2?t=1685517797434') format('woff2'),
    url('//at.alicdn.com/t/c/font_4096975_pswyqyk8tdo.woff?t=1685517797434') format('woff'),
    url('//at.alicdn.com/t/c/font_4096975_pswyqyk8tdo.ttf?t=1685517797434') format('truetype');
}

这段代码定义了一个名为"iconfont"的字体,它来自于阿里云的字体库。

.iconfont {
   
  font-family: "iconfont"!important;
  font-size: 16px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

这段代码定义了一个名为"iconfont"的类,它继承了阿里云字体库中的字体。

.icon-xinlangweibo:before {
   
  content: "\e600";
}

这段代码定义了一个名为"icon-xinlangweibo"的伪元素,它的内容是"\e600",这是一个阿里云字体库中的图标。

.icon-shouji:before {
   
  content: "\e601";
}

这段代码定义了一个名为"icon-shouji"的伪元素,它的内容是"\e601",这是一个阿里云字体库中的图标。

.icon-weixin:before {
   
  content: "\e602";
}

这段代码定义了一个名为"icon-weixin"的伪元素,它的内容是"\e602",这是一个阿里云字体库中的图标。

.icon-jingdong:before {
   
  content: "\e812";
}

这段代码定义了一个名为"icon-jingdong"的伪元素,它的内容是"\e812",这是一个阿里云字体库中的图标。

.icon-taobao:before {
   
  content: "\e755";
}

这段代码定义了一个名为"icon-taobao"的伪元素,它的内容是"\e755",这是一个阿里云字体库中的图标。

.icon-shoujitaobao:before {
   
  content: "\e786";
}

这段代码定义了一个名为"icon-shoujitaobao"的伪元素,它的内容是"\e786",这是一个阿里云字体库中的图标。

.icon-alipay:before {
   
  content: "\e618";
}

这段代码定义了一个名为"icon-alipay"的伪元素,它的内容是"\e618",这是一个阿里云字体库中的图标。

.icon-QQ:before {
   
  content: "\e882";
}

这段代码定义了一个名为"icon-QQ"的伪元素,它的内容是"\e882",这是一个阿里云字体库中的图标。

.icon-douyin:before {
   
  content: "\e8db";
}

这段代码定义了一个名为"icon-douyin"的伪元素,它的内容是"\e8db",这是一个阿里云字体库中的图标。

.icon-pinduoduo:before {
   
  content: "\e8df";
}

这段代码定义了一个名为"icon-pinduoduo"的伪元素,它的内容是"\e8df",这是一个阿里云字体库中的图标。

* {
   
  margin: 0;
  padding: 0;
}

这段代码是用来清除默认的外边距和内边距的。

body {
   
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #e8e8e8;
}

这段代码是用来设置页面的高度、居中显示、背景颜色等样式的。

ul {
   
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  list-style: none;
}

这段代码是用来设置导航栏的位置、居中显示、列表样式等样式的。

ul li {
   
  position: relative;
  margin: 0 2px;
  width: 40px;
  height: 40px;
}

这段代码是用来设置导航栏中的每个图标的位置、间距、宽度、高度等样式的。

ul li span {
   
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  line-height: 40px;
  font-size: 16px;
  background: #fff;
  color: #26262626;
  transform-origin: top;
  text-align: center;
  cursor: pointer;
}

这段代码是用来设置导航栏中的每个图标的文本样式、背景颜色、字体大小、对齐方式等样式的。

ul li span:nth-child(2) {
   
  background: #3b5999;
  color: #fff;
  transform-origin: bottom;
  transform: rotateX(90deg) translateY(50%);
}

这段代码是用来设置导航栏中的第一个图标的悬浮文字的样式、背景颜色、字体大小、对齐方式等样式的。

ul li::before {
   
  content: "";
  position: absolute;
  left: 0;
  bottom: -10px;
  width: 40px;
  height: 8px;
  background: #000;
  border-radius: 50%;
  transition:.5s;
  opacity: 0;
  filter: blur(2px);
  transform: scale(0.8);
}

这段代码是用来设置导航栏中的每个图标的悬浮阴影的样式、位置、大小、背景颜色、圆角半径、过渡效果、透明度、模糊效果、缩放效果等样式的。

ul li:hover::before {
   
  transition-delay:.5s;
  opacity:.2;
  transform: scale(1);
}

这段代码是用来设置导航栏中的每个图标悬浮时悬浮阴影的过渡效果、透明度、缩放效果等样式的。

相关推荐

  1. Uniapp自定义导航

    2024-01-18 14:36:01       37 阅读
  2. uView Tabbar 底部导航

    2024-01-18 14:36:01       44 阅读
  3. css折叠的导航

    2024-01-18 14:36:01       12 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-18 14:36:01       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-18 14:36:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-18 14:36:01       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-18 14:36:01       20 阅读

热门阅读

  1. 达梦数据库 忘记 SYSDBA 密码 处理方法

    2024-01-18 14:36:01       32 阅读
  2. 智能小程序相关名词解释(汇总)

    2024-01-18 14:36:01       35 阅读
  3. uniapp返回上一页并刷新数据

    2024-01-18 14:36:01       33 阅读
  4. MySQL部署

    2024-01-18 14:36:01       28 阅读
  5. jupyter中使用conda环境

    2024-01-18 14:36:01       34 阅读