--- title: CSS · Tab选项卡 summary: 一个纯 CSS 实现的 Tab 选项卡 created: 2022-03-09T07:42:25.299Z tags: - CSS categories: - CSS lastmod: 2022-04-07T07:40:02.371Z --- 一个纯 CSS 实现的 Tab 选项卡 ## 原理 > 通过隐藏的 `input` 和与之关联的 [label](https://so.csdn.net/so/search?q=label&spm=1001.2101.3001.7020) 点击 `label` 触发 `input` 的 `checked` 状态触发的,再配合使用元素状态的伪类 `:checked `样式就可以实现不同状态的切换,中间的过度效果还可以配合 CSS3 的 `transition`过度效果实现 [^1]。 ## 代码 - `input` 的`name` 都一样,`id`不同 ### HTML ```html
THIS IS TAB1 CONTENT
Notice the gap between the content and tab after applying background cololr
THIS IS TAB2 CONTENT
Notice the gap between the content and tab after applying background cololr
THIS IS TAB3 CONTENT
Notice the gap between the content and tab after applying background cololr