【发布时间】:2018-08-16 01:24:02
【问题描述】:
我为画廊类别创建了一系列图片链接。每个“按钮”在背景中都有一个图像,并且画廊标题覆盖它。我已将其设置为更改背景,并且标题也更改为使用 css 悬停时的画廊,但我遇到的问题是高度。正在加载 div 以适应标题,但随后在鼠标悬停时跳得更大以容纳描述文本。我需要它加载足够大以使描述文本很好地适合其中。
我希望它具有响应性,因此文本需要能够换行,并且 div 需要相应地扩展(并且永远不会在鼠标悬停时跳跃高度)。所以高度不能是固定的高度,否则当 div 是全宽时,这些高度会太高。我在这里设置了一个测试
body{
font-family: Arial, Helvetica, sans-serif;
}
.item1{
width: auto;
display: table-cell;
}
a{
text-decoration:none;
}
.label1 {
padding-top: 20px;
padding-bottom: 20px;
text-align: center;
font-size: 24px;
font-weight: bold;
color: #ffffff;
text-transform: uppercase;
white-space: nowrap;
text-decoration: none;
background: url('https://premium.wpmudev.org/blog/wp-content/uploads/2015/02/fullwidth-small.png') no-repeat;
background-position: center top;
background-size: 100% auto;
transition: background 0.5s ease;
}
.label1.success {
background-color: #FFFFFF;
}
.label1:hover {
width: auto;
height: auto;
padding-left: 20px;
padding-right: 20px;
background: #FFFFFF ;
background-position: center top;
background-size: 100% auto;
-webkit-box-shadow:inset 0px 0px 0px 4px #000000;
-moz-box-shadow:inset 0px 0px 0px 4px #000000;
box-shadow:inset 0px 0px 0px 4px #000000;
}
.item1 a p.new-label1 span{
position: relative;
content: 'NEW'
}
.item1:hover a p.new-label1 span{
display: none;
}
.item1:hover a p.new-label1:after{
content:attr(data-title);
white-space: normal !important;
overflow-wrap: normal;
font-size: 14px;
color: #000000;
}
<div style="width: 50%; display: table;">
<div class="item1">
<a href="">
<p class="label1 success new-label1" data-title="I Show up on Hover and have lots and lots of things to say and it takes up too much space" ><span class="align">New</span></p>
</a>
</div>
</div>
<div class="cleafix">
</div>
我也遇到了过渡效果的问题,但这个问题要紧迫得多。也就是说,如果有人想给我一个解决方案,我一点也不介意;)
【问题讨论】:
标签: css hover height mouseover