html - 显示部分/div 取决于链接中散列# 值之后

标签 html css

我有以下页面

section {
 height: 1000px;
 background: yellow;
 margin: 50px;
}
<section id="one">Section one</section>
<section id="two">Section two</section>

如果用户来自包含散列后的部分 ID 的链接,则可以仅使用 html/css 仅显示一个部分,例如

?

最佳答案

您可以调查 :target 的使用情况伪类,但当 URL 哈希为空时,您可能很难显示所有部分。

例如:

section:not(:target) { display:none; }
section:target { display: block }
<a href="#one">One</a>
<a href="#two">Two</a>

<section id="one">Section one</section>
<section id="two">Section two</section>

关于html - 显示部分/div 取决于链接中散列# 值之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54644619/

相关文章:

html - 显示 :none not working in Opera

html - div随内容宽度 float

javascript - 是否可以在 NW.js 中离线保存 html 元素更改?

javascript - 全部选中/取消选中,无布局更改 HTML/JavaScript

php - Codeigniter-在 window.print() 中每页限制 2 个图像

html - Chrome Dev Tools 添加了 <br> 标签,而这些标签不存在?

html - 在 firefox 和其他浏览器中遇到 ul 问题

html - CSS :hover div elements

jquery - 验证后删除错误消息

php - 如何隐藏 div 内容并仅在单击按钮时显示?