【发布时间】:2014-10-30 18:16:07
【问题描述】:
我正在研究 CSS 隐藏/显示效果。它在 Firefox 上运行良好。你点击它,Hello World 文本就会出现。然后你再次点击,它就消失了。
但在 Chrome/Safari 上,您必须点击并按住按钮才能使其显示。
如何让它在 Chrome/Safari 上像在 Firefox 上一样正常工作?
这里是jsfiddle。
HTML:
<div class="formatting_show" id="formatting_show"></div>
<span id="formatting_content"> Hello World </span>
CSS:
#formatting_show {
cursor: pointer;
cursor: hand;
float: right;
font-size: 30px;
height: 15px;
text-align: right;
width: 74px;
color: #000;
}
#formatting_content {
display: block;
-webkit-transition: opacity 1s ease-out;
transition: opacity 1s ease-out;
opacity: 0;
height: 0;
font-size: 0;
overflow: hidden;
}
#formatting_show:before {
content: "Formatting «"
}
#formatting_show:active.formatting_show:before {
content: "Formatting »"
}
#formatting_show:active ~ span#formatting_content {
font-size: 30px;
height: 70px;
opacity: 1;
}
#formatting_content {
float: left;
}
【问题讨论】:
-
我猜
:active在不同浏览器中的实现方式不同 -
@Huangism 你知道如何调整它以使其通用吗?如果你这样做,请提供一个用于测试的小提琴。
-
我会使用 js 来实现这种点击行为,在 webkit 浏览器中,只有在项目上按住鼠标按钮时才会添加活动状态。我认为使用 css 是不可行的
标签: html css google-chrome hide show