html - 如何使工具提示出现在下方而不是覆盖它?
问题描述
当鼠标悬停在此部分上时,此代码显示包含五行信息的工具提示:<div class="event1Bubble tooltip">
<div>
目前,工具提示会在该部分出现时完全隐藏该部分。我希望它直接出现在该部分的下方,以便我的用户可以同时看到该部分和工具提示。
有人可以告诉我如何在不改变任何现有样式的情况下修改我的代码来实现这一点吗?
.Timeline {
display: flex;
align-items: center;
height: 500px;
margin-left: 80px;
}
.event1 {
position: relative;
}
.event1Bubble {
position: absolute;
background-color: rgba(158, 158, 158, 0.1);
width: 130px;
height: 60px;
top: -70px;
left: -15px;
border-radius: 5px;
box-shadow: inset 0 0 5px rgba(158, 158, 158, 0.64)
}
.event1Bubble:after,
.event1Bubble:before {
content: "";
position: absolute;
width: 0;
height: 0;
border-style: solid;
border-color: transparent;
border-bottom: 0;
}
.event1Bubble:before {
bottom: -10px;
left: 13px;
border-top-color: rgba(222, 222, 222, 0.66);
border-width: 12px;
}
.event1Bubble:after {
bottom: -8px;
left: 13px;
border-top-color: #F6F6F6;
border-width: 12px;
}
.eventTime {
display: flex;
}
.DayDigit {
font-size: 27px;
font-family: "Arial Black", Gadget, sans-serif;
margin-left: 10px;
color: #4C4A4A;
}
.Day {
font-size: 11px;
margin-left: 5px;
font-weight: bold;
margin-top: 10px;
font-family: Arial, Helvetica, sans-serif;
color: #4C4A4A;
}
.MonthYear {
font-weight: 600;
line-height: 10px;
color: #9E9E9E;
font-size: 9px;
}
.active {
font-family: "Arial Black", Gadget, sans-serif;
color: #228B22;
font-size: 11px;
text-transform: uppercase;
display: flex;
flex: 1;
align-items: center;
margin-left: 12px;
margin-top: -2px;
}
.tooltip {
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 480px;
background-color: black;
font-family: Arial, Helvetica, sans-serif;
color: #fff;
text-align: left;
padding: 5px 0;
padding-left: 5px;
border-radius: 6px;
position: absolute;
z-index: 1;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
<div class="Timeline">
<div class="event1">
<div class="event1Bubble tooltip">
<span class="tooltiptext">id: 12345</br>
starts_on: 2019-03-07</br>
start_reason: something</br>
ends_on:</br>
end_reason:</br>
type: something
</span>
<div class="eventTime">
<div class="DayDigit">10</div>
<div class="Day">
Wednesday
<div class="MonthYear">September 2018</div>
</div>
</div>
<div class="active">Active</div>
</div>
</div>
</div>
解决方案
只需将top
悬停容器的高度值(在您的情况下为 60px)添加到绝对定位的工具提示元素。
顺便说一句,</br>
是无效标记。在 X(HT)ML 中,它应该是独立<br>
的或自动关闭的。<br/>
.Timeline {
display: flex;
align-items: center;
height: 500px;
margin-left: 80px;
}
.event1 {
position: relative;
}
.event1Bubble {
position: absolute;
background-color: rgba(158, 158, 158, 0.1);
width: 130px;
height: 60px;
top: -70px;
left: -15px;
border-radius: 5px;
box-shadow: inset 0 0 5px rgba(158, 158, 158, 0.64)
}
.event1Bubble:after,
.event1Bubble:before {
content: "";
position: absolute;
width: 0;
height: 0;
border-style: solid;
border-color: transparent;
border-bottom: 0;
}
.event1Bubble:before {
bottom: -10px;
left: 13px;
border-top-color: rgba(222, 222, 222, 0.66);
border-width: 12px;
}
.event1Bubble:after {
bottom: -8px;
left: 13px;
border-top-color: #F6F6F6;
border-width: 12px;
}
.eventTime {
display: flex;
}
.DayDigit {
font-size: 27px;
font-family: "Arial Black", Gadget, sans-serif;
margin-left: 10px;
color: #4C4A4A;
}
.Day {
font-size: 11px;
margin-left: 5px;
font-weight: bold;
margin-top: 10px;
font-family: Arial, Helvetica, sans-serif;
color: #4C4A4A;
}
.MonthYear {
font-weight: 600;
line-height: 10px;
color: #9E9E9E;
font-size: 9px;
}
.active {
font-family: "Arial Black", Gadget, sans-serif;
color: #228B22;
font-size: 11px;
text-transform: uppercase;
display: flex;
flex: 1;
align-items: center;
margin-left: 12px;
margin-top: -2px;
}
.tooltip {
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 480px;
background-color: black;
font-family: Arial, Helvetica, sans-serif;
color: #fff;
text-align: left;
padding: 5px 0;
padding-left: 5px;
border-radius: 6px;
position: absolute;
z-index: 1;
top: 60px;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
<div class="Timeline">
<div class="event1">
<div class="event1Bubble tooltip">
<span class="tooltiptext">id: 12345<br>
starts_on: 2019-03-07<br>
start_reason: something<br>
ends_on:<br>
end_reason:<br>
type: something
</span>
<div class="eventTime">
<div class="DayDigit">10</div>
<div class="Day">
Wednesday
<div class="MonthYear">September 2018</div>
</div>
</div>
<div class="active">Active</div>
</div>
</div>
</div>
推荐阅读
- visual-studio-code - 你如何在 VSCode 中取消拆分终端?
- r - 如何从字符串中删除未知符号?
- python - 如何在 tkinter 中将多个按钮链接到一个文本小部件?
- excel - ActiveWorkbook.Queries.Add 筛选条件
- python - 从我正在使用图像管道的scrapy spider下载/抓取图像时,我遇到了一个值错误
- php - Laravel 队列无法发送邮件
- python - 从文件中读取 16 字节 Fortran 浮点数到 Python
- php - laravel 选择框值显示
- h2o - 使用 H2OFlow 解释增益/提升图
- forms - Symfony Forms 将占位符添加到集合字段的原型中