javascript - css 在悬停时将隐藏更改为可见

标签 javascript html css

<分区>

我想隐藏页面上的一些评级文本,直到我将鼠标悬停在它上面。

我是新手 css + javascript 编码器,我在查看网页时正在测试一些 css 覆盖代码(例如使用带有 stylebot 扩展的 chrome 浏览器),这意味着您只能修改 css。我没有找到使用 css visibility 属性执行此操作的方法,但使用 opacity 效果很好,请参见下面的代码。我找不到任何解释为什么当我将鼠标悬停在该区域上时 css visibility 不会改变的原因。只是好奇是否有人可以解释它。是否可以仅在 css 中处理visibility

如果我通过 javascript 更改可见性,此行为是否与纯 css 相同?我在 stackoverflow.com 上看到几个问题,询问看起来类似的问题,但确实遵循了这些问题。只是好奇。

(编辑:我先尝试了display,然后尝试了visibility。我意识到空间保持可见性但悬停被禁用了?)。

<!DOCTYPE html>
<html>
<head>
<style>
div.mydiv1 {
    visibility:hidden;
}
div.mydiv1:hover {
    visibility:visible;
}

div.ratingValue {
    opacity: 0
}
div.ratingValue:hover {
    opacity:1;
}
</style>

</head>
<body>
Opacity:
<div class=ratingValue>
  Opacity example
<p />
</div>
Visibility:
<div class=mydiv1>
    Visibility example
</div>
</body>
</html>

最佳答案

查看规范:

visibility: hidden The element box is invisible (not drawn), but still affects layout as normal. Descendants of the element will be visible if they have visibility set to visible. The element cannot receive focus (such as when navigating through tab indexes).


display: none Lets you turn off the display of an element; when you use none, all descendant elements also have their display turned off. The document is rendered as though the element doesn't exist in the document tree.

关于javascript - css 在悬停时将隐藏更改为可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47619928/

上一篇:html - 调整浏览器大小时如何使选择输入缩小?

下一篇:CSS 动画转发阻止了 css 转换

相关文章:

javascript - Javascript 中的日期格式

javascript - 文本框 Uncaught TypeError : Super expression must either be null or a function, not undefined

html - 文本显示通过固定的 div 出现

jquery - CSS/jQuery 多级列表

javascript - 1.9px 文本大小显示为 1px - Raphael SVG、CSS、Javascript

javascript - Cypress - 在页面导航之前测试点击事件

php - 是否可以使用 PHP 或 JavaScript 从用户处获取剪贴板数据?

javascript - 替换javascript字符串中的欧姆符号(Ω)

javascript - 如何从 API JSON 数据创建下拉菜单

html - 使用表格单元格的百分比宽度相等