我为图库类别创建了一系列图片链接。每个“按钮”在背景中都有一个图像,而图库标题覆盖了这个图像。我已将其设置为更改背景,并且标题也会在使用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>
我也遇到过转换效果问题,但这个问题要紧迫得多。也就是说,如果有人想给我一个解决方案,我根本不介意;)
答案 0 :(得分:0)
我不知道这正是你想要的,但我以我的理解做了演示。它可能会有所帮助
body {
font-family: Arial, Helvetica, sans-serif;
}
.item1 {
width: auto;
display: table-cell;
}
a {
text-decoration: none;
}
.label1 {
position: relative;
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: cover;
transition: all .4s;
margin: 0;
}
.label1.success {
background-color: #fff;
}
.item1:hover .label1 {
}
.item1 a p.new-label1 span {
content: 'NEW';
position: absolute;
right: 0;
left: 0;
top: 50%;
transform: translateY(-50%);
opacity: 1;
visibility: visible;
transition: all .4s;
}
.item1:hover a p.new-label1 span {
opacity: 0;
visibility: hidden;
}
.item1 a p.new-label1:after {
content: attr(data-title);
background-color: transparent;
white-space: normal;
overflow-wrap: normal;
font-size: 14px;
color: #000;
padding: 20px 10px;
opacity: 0;
visibility: hidden;
display: block;
transition: all .4s;
}
.item1:hover a p.new-label1:after {
content: attr(data-title);
background-color: #fff;
opacity: 1;
visibility: visible;
-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;
}
&#13;
<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>
&#13;