纯css导航下拉

The appearence of “tab” navigation is relatively easy to create, but making a tab bring up its own content without moving to a new page is more complex, especially if you want to activate it on click, rather than hover… particularly if you are determined to only use CSS. Thankfully, the :target selector can do much of the work for us.

“标签”导航的出现相对容易创建,但是要使标签在不移动到新页面的情况下显示其自身的内容则更为复杂,尤其是如果您想单击而不是将其悬停激活的话。确定仅使用CSS。 幸运的是, :target选择器可以为我们完成很多工作。

First, let’s create some basic markup. Let’s say we were going to create a series of slides about some of Saturn’s moons: Titan, Mimas, Enceladus and Iapetus. I’ll use markup similar to the simple CSS image gallery: the names of the moons are clickable definition terms, and the explanation of each is a definition declaration.

首先,让我们创建一些基本标记。 假设我们要制作一系列有关土星卫星的幻灯片:土卫六,Mimas,土卫二和Iapetus。 我将使用类似于简单CSS图像库的标记:卫星名称是可单击的定义术语,每个术语的解释都是定义声明。

<dl id="moons"><dt><a href="#titan">Titan</a><dd id="titan"><img src="titan.jpg" alt="Titan"><p>Saturn's largest moon is unique in several respects.</dd><dt><a href="#iapetus">Iapetus</a><dd id="iapetus"><img src="iapetus.jpg" alt="Iapetus"><p>Iapetus is the third largest moon of Saturn.</p></dd>
</dl>

Note the id value on each <dd>, and the href links within each <dt>. These go to anchor links, just as we have explored in the past. Next, the associated CSS to produce the basic appearance of the tabs: I've written this in Sass, but vanilla CSS would work too:

注意每个<dd>,上的id<dd>,以及每个<dt>内的href链接。 正如我们过去所探讨的那样,这些链接用于锚定链接 。 接下来,使用关联CSS来生成选项卡的基本外观:我已经用Sass编写了此代码,但是普通CSS也可以使用:

$bgcolor: #222;
* {box-sizing: border-box;
}
body {margin: 3rem;background: $bgcolor;
}
dl#moons { line-height: 1.5;font-family: Avenir, sans-serif;position: relative;width: 50rem;dt { display: inline-block; margin-right: .5rem;position: relative;z-index: 5;a { text-decoration: none; padding: 1rem;border: 1px solid black;background: #555;display: block;min-width: 8rem;font-weight: 600;border-radius: 10px 10px 0 0;&:hover, &:focus { background: #222;}&:visited {background: #aaa;}}}

Then the <dd> elements and their content. I've added a border-top to the <dd> elements to provide the impression that the tabs are positioned above the <dd> tags; in reality, they both start at the same point. This is done to counteract the jump behavior associated with anchor links: without it, the page would scroll instantly to the position of the associated panels after a click, obscuring the tabs. As it is, activated tabs will always be forced to the very top of the page.

然后是<dd>元素及其内容。 我在<dd>元素上添加了一个border-top以使选项卡位于<dd>标记上方; 实际上,它们都是从同一点开始的。 这样做是为了抵消与锚链接相关联的跳转行为:没有它,页面将在单击后立即滚动到关联面板的位置,从而使选项卡模糊。 实际上,激活的选项卡将始终被强制到页面的顶部。

I've also provided the images with a circle wrap to make the best use of the limited space inside each info window.

我还为图像提供了一个圆圈包装,以充分利用每个信息窗口内的有限空间。

dd { position: absolute; left: 0; margin-left: 0;top: 0;padding: 2rem 1rem 1rem 1rem;border-top: 3.6rem solid $bgcolor;width: 100%;background: #000;color: white;opacity: 0;transition: .3s opacity;a { color: white;}img { max-width: 100%; float: right; margin: 1rem;shape-outside: circle();}}
}

target makes CSS aware of the relationship between elements with id attributes and links to those elements. One opportunity this affords us to change the state of the target when the associated link is clicked on: in this case, its z-index and opacity:

target使CSS知道具有id属性的元素之间以及与这些元素的链接之间的关系。 一个机会使我们可以在单击关联的链接时更改目标的状态:在这种情况下,它的z-indexopacity

dd#titan:target, dd#iapetus:target, dd#enceladus:target,dd#mimas:target { z-index: 4; opacity: 1;
}

We could make any of the information windows appear by default by sharing the appropriate anchor in a URL; for example: http://thenewcode.com/291/Pure-CSS-Tab-Navigation#iapetus

通过在URL中共享适当的锚点,我们可以使任何信息窗口默认显示。 例如: http : //thenewcode.com/291/Pure-CSS-Tab-Navigation#iapetus

Alternatively, we could use JavaScript to activate one of the tabs by default:

另外,我们可以默认使用JavaScript激活选项卡之一:

document.querySelector('a[href="#titan"]').click();

翻译自: https://thenewcode.com/291/Pure-CSS-Tab-Navigation

纯css导航下拉

纯css导航下拉_纯CSS标签导航相关推荐

  1. html用css做下拉菜单,纯css实现下拉菜单

    纯css实现下拉菜单 1.效果如下: 2.html代码 时间最近 时间最近 评论最多 被赞最多 3.css代码 * { margin: 0; padding: 0; } ul { list-style ...

  2. 纯CSS实现下拉菜单及下拉容器等(纯CSS实现导航条及导航下拉容器)

    原文:纯CSS实现下拉菜单及下拉容器等(纯CSS实现导航条及导航下拉容器) 虽然网上类似甚至相同的案例有很多,但是我还是写下,以记下笔记,也可供大家参考 希望大家可以指导批评~~ 首先我们以列表ul ...

  3. html实现导航下拉菜单绝对定位,纯CSS导航下拉效果,神奇的定位与显示属性

    导航下拉,大家首先想到的是用JS来做.或许是大家看到的下拉菜单演示,多是JS控制的下拉,导致从先入为主的意识上,误以为二级下拉是很难的东西,必须要会Javascript才能做. 其实,一个简答的下拉效 ...

  4. html下拉菜单触摸显示,CSS导航:纯CSS触碰式下拉菜单

    [破洛洛教学网] 纯CSS触碰式下拉菜单 /* 整体设置*/ .navigation { margin:0; padding:0; width:610px; list-style-type:none; ...

  5. 兼容IE各版本的纯CSS二级下拉菜单

    这是一个标准的CSS下拉菜单制作教程,有针对目前流行的IE6/IE7/IE8不同版本的CSS代码,因此可以在IE之间完全兼容,不过其它的浏览器像火狐/GG浏览器之类的没有测试,如果兼容IE8的话,那么 ...

  6. 纯css 下拉选择,纯CSS实现的下拉菜单

    实现效果 实现代码 html home wordpress themes plugins tutorials web design resources links tutorials html/css ...

  7. html鼠标经过自动下拉菜单,操作方法:在鼠标经过后使用纯CSS实现下拉菜单,并附有示例说明(代码)...

    纯CSS实现鼠标移动到按钮上打开下拉菜单. CSS部分: .dropbtn { background-color: #4CAF50; color: white; padding: 16px; font ...

  8. 纯css写下拉箭头,三角,半圆。

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. CSS 制作下拉导航

    下拉菜单仍然是Web上流行的界面元素,虽然有一些纯Javascript 解决方案,但在禁用Javascript 的浏览器下,它却无能为力.因此,纯CSS的下拉菜单才是最好的选择. 这种技术及其简单,只 ...

最新文章

  1. 【Spring】23、ApplicationContext ,ApplicationContextAware,Listener,Event 的关系解读
  2. 没有form的表单验证_PHP动态生成表单,内置17种常用组件并且支持表单验证!
  3. 如何快速设计短信验证码
  4. libgo 支持mysql,loadrunner通过使用libmysql.dll完成mysql的测试-Go语言中文社区
  5. java中“53”个关键字(含2个保留字)
  6. php将变量转成字符串类型
  7. 谷歌将推出新版Pixel 4a 5G:搭载骁龙765G处理器 售价下降至3200元
  8. mongodb的安装和sql操作
  9. python入门基础语法答案_第一阶段:Python开发基础 Python基础语法入门  day03 课后作业...
  10. 如何导出久其报表所有数据_【久其报表数据管理系统怎么用】久其报表数据管理系统好不好_使用技巧-ZOL软件百科...
  11. 【Java编程】写一个将华氏温度转换成摄氏温度的程序,转换的公式是:°F = (9/5)*°C + 32 其中C表示摄氏温度,F表示华氏温度。
  12. 第一篇 ME909S-821开始使用
  13. 服务器上设置密码策略不能修改,Window Server 2008 R2 在Active Directory域中不能更改服务器密码策略...
  14. 能够关闭并退出计算机程序的是,电脑强制关闭程序按哪三个键 可按Alt+F4关闭当前页面...
  15. 决策树的ID3算法的应用
  16. 医院信息管理系统论文java_毕业论文-基于java的医院门诊信息管理系统设计与实现...
  17. 西门子主程序调用子程序_西门子PLC如何在主程序,写入调用子程序的命令?
  18. IEEE letter,magazine,journal/transaction
  19. Windows之应用安装程序 —— winget
  20. matlab求解一维波动方程,一维波动方程matlab

热门文章

  1. Java中的JavaCore/HeapDump文件及其分析方法
  2. 最全最强的DELL Leopard综合帖(系统+驱动+问题+进阶+软件) 08.8.11更新
  3. 怎么设置电脑的开机关机时间
  4. python图片识别之 easyocr
  5. zstack流程梳理与串口事件详解及zigbee调试助手实现细节
  6. Java程序员的重启人生-2.完美级冒泡排序丹
  7. 【王道数据结构】思维导图--5.2二叉树的概念(高清)
  8. OpenHarmony开发者文档 获取工具.md HUAWEI DevEco Studio下载地址 HUAWEI DevEco Device Tool下载地址
  9. 统计信号处理基础 习题解答1-3
  10. @Bean注解的使用和详解