【发布时间】:2015-04-03 13:41:10
【问题描述】:
我正在使用纯 CSS 而不是 Javascript 实现可关闭的 <div>。
HTML 和 CSS:
<!DOCTYPE html>
<html>
<head>
<style>
div.messages
{
padding: 10px;
background-image: none;
border: 1px solid transparent;
border-color: #bce8a1;
border-radius: 5px;
width: 300px;
}
div.messages:before
{
content: "\274C";
float: right;
cursor: pointer;
}
div.messages:active
{
height: 0px;
display: none;
}
</style>
</head>
<body>
<div class= "messages">
In publishing and graphic design, lorem ipsum is a filler text commonly used to demonstrate the graphic elements of a document or visual presentation. Replacing meaningful content that could be distracting with placeholder text may allow viewers to focus on graphic aspects such as font, typography, and page layout. It also reduces the need for the designer to come up with meaningful text, as they can instead use hastily generated lorem ipsum text.
</div>
</body>
</html>
代码有效(有点),但我有一些注释想寻求帮助
- 关闭在 Firefox 上运行正常; Chrome 似乎也关闭了,但只要松开鼠标,
<div>就会重新出现 - 每当我单击其范围内的任何位置时,
<div>都会闪烁。如何让它继续显示?
【问题讨论】:
-
reappears as soon as the mouse is released是:active的行为 -
使用 CSS 无法永久更改对象
onclick的状态。只有当您希望在按住鼠标按钮时发生某些事情时,Active 才真正有用。 -
这是否意味着我必须使用 Javascript?
标签: html css google-chrome firefox