纯css实现选项卡

纯css实现一个选项卡

先看代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>演示文档</title>
    <style>
		body{
			padding: 100px;
		}
       *{
		   margin: 0;
		   padding: 0;
	   }
	   .clear{
		   clear: both;
	   }
	   ul{
		   list-style-type: none;
	   }
	   a{
			float: left;
			border: 1px solid orange;
			background-color: pink;
			width: 100px;
			text-decoration: none;
			box-sizing: border-box;
	   }
	   a:hover{
		   background-color: red;
	   }
	   .content {
		   width: 300px;
		   height: 300px;
		   background-color: deeppink;
		   overflow: hidden;
	   }
	   .content div{
		   width: 100%;
		   height: 100%;
	   }
    </style>
</style>
</head>
<body>
    <div class="tab">
		<ul>
			<li><a href="#con1">菜单一</a></li>
			<li><a href="#con2">菜单二</a></li>
			<li><a href="#con3">菜单三</a></li>
		</ul>
	</div>
	<div class="content clear">
		<div id="con1">选项卡1......</div>
		<div id="con2">选项卡2......</div>
		<div id="con3">选项卡3......</div>
	</div>
</body>
</html>

在这里插入图片描述

总结重点

  1. a标签href="#id" 这里链接对应的选项快
  2. 将选项内容大的div容器设置宽高度,超出部分隐藏。这样每次选中对应的选项区,则会跳转到该选项块
  3. 可以先将overflow设置为auto看看是如何工作的
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值