【发布时间】:2017-11-28 13:40:08
【问题描述】:
我很难理解为什么我的容器(表格单元格)的行为不像我希望的那样:)
情况:我创建了一个 div 容器(bouton),里面有 2 个 div(图像和文本)。 我想要什么:将鼠标悬停在容器上的任何位置都会应用背景色。 问题:我在 div 容器 (bouton) 中添加了一个背景色悬停,但不是仅将其应用于所有 div“bouton”,而是将其应用于所有行。
这是小提琴:https://jsfiddle.net/gicspy/qotv4yz0/3/
HTML:
<div id="bouton">
<a href="/test/" title="test">
<div class="bouton-image">
<img class="clear-btn-devis" src="http://via.placeholder.com/100x120" width="100" height="120">
</div>
<div class="bouton-texte">
THIS IS CONTENT FOR THE BUTTON
<br /><span style="font-size:90% !important;"><p style="line-height: 1 !important;">(with more information even)</p></span>
</div>
</a>
</div>
CSS:
#bouton div {
display: table-cell;
cursor: pointer;
background-color: #1ac658;
color: #ffffff !important;
padding: 5px;
border: 0px;
margin: 4px 2px;
margin-top: 20px;
margin-bottom: 20px;
text-align: center;
vertical-align: middle;
max-width: 300px;
}
.bouton-image {
display: table;
border-radius: 3px 0px 0px 3px;
min-width: 70px !important;
margin: auto;
text-align: center;
overflow: hidden;
}
.bouton-texte {
border-radius: 0px 3px 3px 0px;
font-size: 130%;
text-decoration: none;
font-weight: bold;
}
#bouton:hover,
#bouton:active {
-webkit-transition-duration: 0.4s;
background-color: #f6416c !important;
box-shadow: 0 6px 13px 0 rgba(0, 0, 0, 0.2), 0 4px 16px 0 rgba(0, 0, 0, 0.19);
}
我一直在寻找,但我错过了有关表格单元格行为方式的一些信息。
有人可以帮忙吗?
非常感谢,
【问题讨论】:
-
text-align、inline-block 和 vertical-aline 很好:jsfiddle.net/qotv4yz0/4 ;) 指针事件和显示 用于悬停效果 jsfiddle.net/qotv4yz0/5