且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

正常显示截断的文本,但悬停时显示全文

更新时间:2023-11-01 13:35:04

下面的CSS将使div覆盖其下面的所有内容,因此它

The CSS below will cause the div to "cover" everything below it so it doesn't push any content down.

position: absolute;
background-color:#FFF;

背景颜色很重要,因此您看不到下面的内容。

The background color is important so you can't see the stuff below.

要确保所有内容都位于同一位置,可以为下一个元素提供与行高相同值的上边距。 + 符号是相邻的兄弟选择器。

To make sure everything stays in the same place, you can give the next element a top margin of the same value as the line height. The + sign is the adjacent sibling selector.

div {
    line-height: 20px;
}
#data:hover+div {
    margin-top:20px;
}

演示