html - 内容后面的 CSS 下拉菜单
问题描述
我正在尝试创建一个评论列表并提供一个下拉菜单,其中包含每个评论的操作。
我遇到了一个问题,下拉菜单放在下一条评论的文本后面。当您将鼠标悬停在评论上时,您会看到 3 个菜单点出现,将鼠标悬停在这些点上,菜单将在第二条评论后面展开。
几个小时以来,我一直在搞乱元素的 z-index、不透明度和位置,现在正碰壁。可以用其他的眼睛来看看我错过了什么......我知道它必须很简单
.post-comment {
display: flex;
flex-flow: row nowrap;
margin: 20px 0;
min-height: 40px;
}
.post-comment:hover > .options > button {
display: block;
}
.post-comment > .options {
margin: 0 0 0 20px;
min-width: 45px;
position: relative;
z-index: 1;
}
.post-comment > .options > button {
border: none !important;
background-color: rgba(0,0,0,0) !important;
min-width: 45px;
display: none;
}
.post-comment > .options > button > span {
width: 4px;
height: 4px;
border-radius: 50%;
display: block;
background-color: #727272;
margin: 2px;
}
.post-comment > .options > div {
display: none;
position: absolute;
z-index: 999;
}
.post-comment > .options > div > a {
padding: 10px 5px;
border: 1px solid #d5d5d5;
color: #535353 !important;
font-size: 14px;
display: block;
}
.post-comment > .options > div > a:hover {
background-color: #f6f6f6;
}
.post-comment > .options > button:hover {
cursor: pointer;
}
.post-comment > .options > button:hover > span {
background-color: #505050;
cursor: pointer;
}
.post-comment > .options > button:hover + div, .post-comment > .options > div:hover {
display: block;
}
<div class="post-comment">
<div>
Author 2 hour ago<br/>
Some juicy content. Some juicy content. Some juicy content.
</div>
<div class="options">
<button>
<span></span><span></span><span></span>
</button>
<div>
<a href="#1">Option1</a>
<a href="#2">Option2</a>
</div>
</div>
</div>
<div class="post-comment">
<div>
Author 2 hour ago<br/>
Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content.
</div>
<div class="options">
<button>
<span></span><span></span><span></span>
</button>
<div>
<a href="#1">Option1</a>
<a href="#2">Option2</a>
</div>
</div>
</div>
解决方案
您不需要z-index
,只需添加background-color
到您的div
.post-comment {
display: flex;
flex-flow: row nowrap;
margin: 20px 0;
min-height: 40px;
}
.post-comment:hover > .options > button {
display: block;
}
.post-comment > .options {
margin: 0 0 0 20px;
min-width: 45px;
position: relative;
z-index: 1;
}
.post-comment > .options > button {
border: none !important;
background-color: rgba(0,0,0,0) !important;
min-width: 45px;
display: none;
}
.post-comment > .options > button > span {
width: 4px;
height: 4px;
border-radius: 50%;
display: block;
background-color: #727272;
margin: 2px;
}
.post-comment > .options > div {
display: none;
position: absolute;
z-index: 999;
}
.post-comment > .options > div > a {
padding: 10px 5px;
border: 1px solid #d5d5d5;
color: #535353 !important;
font-size: 14px;
display: block;
}
.post-comment > .options > div > a:hover {
background-color: #f6f6f6;
}
.post-comment > .options > button:hover {
cursor: pointer;
}
.post-comment > .options > button:hover > span {
background-color: #505050;
cursor: pointer;
}
.post-comment > .options > button:hover + div, .post-comment > .options > div:hover {
display: block;
}
.options > div {
background-color: #ffffff;
}
<div class="post-comment">
<div>
Author 2 hour ago<br/>
Some juicy content. Some juicy content. Some juicy content.
</div>
<div class="options">
<button>
<span></span><span></span><span></span>
</button>
<div>
<a href="#1">Option1</a>
<a href="#2">Option2</a>
</div>
</div>
</div>
<div class="post-comment">
<div>
Author 2 hour ago<br/>
Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content. Some juicy content.
</div>
<div class="options">
<button>
<span></span><span></span><span></span>
</button>
<div>
<a href="#1">Option1</a>
<a href="#2">Option2</a>
</div>
</div>
</div>
推荐阅读
- r - 无法在 R-studio 中读取 Excel 文件
- jsf - 单击后禁用 a4j:commandButton
- python - 我收到此错误:“UnboundLocalError:分配前引用的局部变量'Requesting_books'”
- crystal-reports - 使用 Oracle 的 Crystal 报表中缺少右括号
- c++ - 在多图中搜索一系列键
- java - 如何创建包含来自目标/生成源的类的 Spring Boot fat JAR
- postgresql - golang ORM 表名
- html - 如何在悬停时有条件地将 css 应用于 mat-row 元素?
- database - 反应原生 react-native-sqlite-storage 不工作
- python - 如何在 fastai 中为 get_transform 添加附加变换?