html - 悬停时展开顶部栏以显示导航链接

标签 html css

我正在尝试让顶部栏在悬停时展开以显示隐藏的文本,这些文本可能是社交媒体图标、导航链接等。

但是我不确定如何隐藏出现在下方 div 上的文本。

这是我的(简单的)代码

html

<div class = "top"> This is the top
<div class = "invisible">can you see me</div>
</div>


<div class = "container">
<div class = "left">left</div>
<div class = "right">right</div>


</div>


This is my css

.top {
width : 100%;
background : blue;
padding-bottom : 25px;
position : relative;
}

.invisible {
position : absolute;
overflow: hidden;
top : 90%;
}

.top:hover {
padding-bottom : 150px;
background : yellow;

}

.container {
display : flex;
}

.left {
width : 50%;
background : red;
}

.right {
width : 50%;
background : green;
}

如您所见,在悬停之前“你能看到我吗”出现在“左侧”文本上

最佳答案

您需要将 overflow: hidden; 移动到父元素 (.top) 因为它是子元素,.invisible溢出到 .top 之外。

.top {
  width: 100%;
  background: blue;
  padding-bottom: 25px;
  position: relative;
  overflow: hidden;
}

.invisible {
  position: absolute;
  top: 90%;
}

.top:hover {
  padding-bottom: 150px;
  background: yellow;
}

.container {
  display: flex;
}

.left {
  width: 50%;
  background: red;
}

.right {
  width: 50%;
  background: green;
}
<div class="top"> This is the top
  <div class="invisible">can you see me</div>
</div>

<div class="container">
  <div class="left">left</div>
  <div class="right">right</div>
</div>

关于html - 悬停时展开顶部栏以显示导航链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44087793/

相关文章:

javascript - 做单选按钮的正确方法?

css - 在浏览器中编辑时保留 css

html - CSS 自动改变 ul 宽度;适合 child inline-block li 的最小宽度?

php - 获取 contenteditable div 的当前值并更新数据库

c# - 如何使下拉列表在下拉列表的顶部而不是底部显示选定的值?

css - 更改 Rails 中 datetime_select 字段的大小

javascript - 更改 react 状态的单个变量

html - 难以跨越一排到全高

javascript - 按钮和 JavaScript 列表

php - 使用 href 到两个链接(php 和网页)