滑动按钮(固定宽度)

84 篇文章 0 订阅

滑动按钮(固定宽度)

教程地址原文地址(YouTube)

B站教程原文转载(bilibili)

两个视频的内容相同,第二个为转载

效果图

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xMI066f3-1581038272770)(演示.gif)]

代码区

html

  <nav>
		<a href="#">Home</a>
		<a href="#">About</a>
		<a href="#">Blog</a>
		<a href="#">Portfolio</a>
		<a href="#">Contact</a>
		<div class="animation start-home"></div>
	</nav>

CSS

body {
  font-family: 'Open Sans', sans-serif; /* 字体 */
  background: #2c3e50; /* 背景 */
}

nav {
  position: relative; /* 相对定位 */
  margin: 270px auto 0; /* 外边距 */
  width: 590px; /* 宽度 */
  height: 50px; /* 高度 */
  background: #34495e;
  border-radius: 8px; /* 边框圆角 */
  font-size: 0; /* 字体大小 */
  box-shadow: 0 2px 3px 0 rgba(0, 0, 0, .1); /* 阴影 */
}
nav a {
  font-size: 15px;
  text-transform: uppercase; /* 大写 */
  color: white; /* 字体颜色 */
  text-decoration: none; /* 字体附加效果 */
  line-height: 50px; /* 行高 */
  position: relative; /* 相对定位 */
  z-index: 1; /* 层叠顺序 */
  display: inline-block; /* 行内盒模型 */
  text-align: center; /* 字体居中 */
}
nav .animation {
  position: absolute; /* 绝对定位 */
  height: 100%;
  top: 0;
  z-index: 0;
  background: #1abc9c;
  width: 100px;
  border-radius: 8px;
  transition: all .5s ease 0s; /* 过渡时间 */
}
a:nth-child(1) { /* 第一个元素a */
  width: 100px;
}
nav .start-home, a:nth-child(1):hover~.animation {
  width: 100px;
  left: 0;
}
a:nth-child(2) {
  width: 110px;
}
nav .start-about, a:nth-child(2):hover~.animation {
  width: 100px;
  left: 100px;
}
a:nth-child(3) {
  width: 100px;
}
nav .start-blog, a:nth-child(3):hover~.animation {
  width: 100px;
  left: 210px;
}
a:nth-child(4) {
  width: 160px;
}
nav .start-portfolio, a:nth-child(4):hover~.animation {
  width: 160px;
  left: 310px;
}
a:nth-child(5) {
  width: 120px;
}
nav .start-contact, a:nth-child(5):hover~.animation {
  width: 120px;
  left: 470px;
}

JS


教程地址原文地址(YouTube)

B站教程原文转载(bilibili)

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值