【发布时间】:2016-11-16 23:23:54
【问题描述】:
我有 5 个框,其中包含在悬停时会发生变化的文本。
但是,如果一个框的“内容”不止一行,它会将其他框略微向下推。
另外,如何使内容垂直居中? Line-height 可以胜任,但有些文本不止一行。垂直对齐似乎也适用于整个 div 而不仅仅是内容中的文本
.image {
width: 204px;
height: 204px;
background-image: url('imglink');
display: inline-block;
background-repeat: no-repeat;
margin-left: 22px;
margin-right: 22px;
font-family: "Verdana", Geneva, sans-serif;
color: white;
font-size: 11pt;
}
.image:hover{
cursor: pointer;
}
.image:after {
width: 204px;
height: 204px;
display: inline-block;
background-repeat: no-repeat;
/* Content is inserted */
content: 'This text is already there';
}
.image:hover:after{
background-image: url('/imglink');
cursor: pointer;
content: 'This text will appear on hover';
}
<div class="image">
</div>
这是 CSS,除了内容不同之外,所有 5 个框都相同。 将其排序为在 Google 上搜索“内容”时遇到巨大困难并没有真正想出 CSS“内容”
这是一个小提琴:https://jsfiddle.net/su8bytdc/7/
【问题讨论】:
-
除了垂直对齐之外,我不完全确定您要完成什么。你能摆弄它吗? jsfiddle.net
-
@Gacci 是的,这是小提琴:jsfiddle.net/su8bytdc/7。如您所见,如果将鼠标悬停在其中一个上,其他的就会下降
-
尝试为
.image定义line-height: 204px; -
最大高度:204px;溢出:隐藏; for .image 也可以提供帮助。
-
@Banzay Line-height 确实很好地居中对齐,但是我有一些 2 行长的文本:/ 所以我必须找到不同的方式