html - 使用 CSS 显示/隐藏内容。我如何隐藏默认值

标签 html css

我试图在用户点击 [...] 之前隐藏网页上的某些内容。到目前为止,Google 已经为我提供了以下内容

<p>some text I want to show</p>
<a href="#" class="hide">[...]</a>
<a href="#" class="show">[...]</a>
<div id ="list">
<p>content I want to hide</p>
</div>

CSS

.show {display: none; }
.hide:focus + .show {display: inline; }
.hide:focus { display: none; }
.hide:focus ~ #list { display:none; }
@media print { .hide, .show { display: none; } }

它可以工作,但我希望将隐藏设置为默认设置,但我似乎无法弄清楚如何实现它。

一如既往,我们将不胜感激。

最佳答案

只需像下面这样更改 css 即可。

首先隐藏列表。并在焦点显示上。

.show {display: none; }
#list { display:none; }
.hide:focus + .show {display: inline; }
.hide:focus { display: none; }
.hide:focus ~ #list { display:block; }

Fiddle

关于html - 使用 CSS 显示/隐藏内容。我如何隐藏默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36002026/

相关文章:

html - 在 Bootstrap 中居中一行

CSS 布局在 iPhone/iPad 上向右移动?

c# - 我应该将 .less 文件放在 Visual Studio Web 应用程序中的什么位置?

css - 如何使用 selectize.js jquery 插件为 select 设置自定义高度和宽度?

html - 使用 html 和 css 的字体大小问题

javascript - 在 JavaScript 中清除特定时间限制后的间隔

javascript - 使用 javascript 从 JSON 文件搜索并从本地存储加载

html - 做 css 动画的另一种方法是什么

Javascript 如何在用户尝试退出或刷新页面时触发函数

html - 为我的页脚添加底部边框和图标