<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>无标题文档</title> | |
<style type="text/css"> | |
button{ resize:both; } | |
.box{ width:200px; height:100px; overflow:hidden; text-align:center;margin-left:8px;} | |
#one {font-size:5em; background:#ccc; width:200px; height:100px; text-align:center;} | |
#two {font-size:5em; background:#f00; width:200px; height:100px; text-align:center;} | |
#three {font-size:5em; background:#0f3; width:200px; height:100px; text-align:center;} | |
#four {font-size:5em; background:#ff3; width:200px; height:100px; text-align:center;} | |
a{ text-decoration:none; } | |
</style> | |
</head> | |
<body> | |
<div class="box"> | |
<div id="one">1</div> | |
<div id="two">2</div> | |
<div id="three">3</div> | |
<div id="four">4</div> | |
</div> | |
<div> | |
<button><a href="#one">按钮1</a></button> | |
<button><a href="#two">按钮2</a></button> | |
<button><a href="#three">按钮3</a></button> | |
<button><a href="#four">按钮4</a></button> | |
</div> | |
</body> | |
</html> |
用锚点加overflow实现“选项卡”技术
锚点可以用来快速定位
锚点定位的本质是改变容器的滚动高度
锚点会定位对应id的元素
overflow与锚点技术:
1、锚点定位的本质是:改变容器的滚动高度
2、锚链接时,如下面的例子
给class="box"添加一个overflow:auto;样式
点击下面的1,2,3,4,能看见随着滚动条的移动转移到不同的div的位置
当改为overflow:hidden;
滚动条不见了,点击下面的1,2,3,4,直接进行div的转换,看不到之前的滚动变换效果
但是这样div切换时,位置会上下偏移,不太好控制
纯css选项卡!
利用锚点 及 overflow实现选显卡!