CSS之3D导航栏

39 篇文章 0 订阅

演示

图片

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

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);
}

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

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值