我看到顶部和底部定位之间存在奇怪的差异。我整理了四个简单的例子来演示这个问题:
//example 1
$('#box1').hover(function () {
var offset = $('#box1').offset();
$("#containment-wrapper1").css({
bottom: offset.top
});
});
//example 2
$('#box2').hover(function () {
var x = $('#box2').css('top');
$("#containment-wrapper2").css({
bottom: x
});
});
//example 3
$('#box3').hover(function () {
var x = $('#box3').css('top');
$("#containment-wrapper3").css({
top: x
});
});
//example 4
$('#box4').hover(function () {
var offset = $('#box4').offset();
$("#containment-wrapper4").css({
top: offset.top
});
});
示例 3 和 4 的行为符合预期,顶部边框与底部边框对齐。
示例 1 和 2 没有。似乎有大约 30 像素的差异。
这是一个错误还是我错过了什么?