在尝试查找clientWidth时,绝对位置会混淆一切

时间:2012-10-22 02:33:53

标签: javascript css

确定。因此,要获得clientWidth,您必须添加代码

#menuSystem a{
position: absolute;
height: auto;
width: auto;
font-size: 15px;
}

您需要这样做,甚至有资格确定客户端宽度。我想要做的是将与链接相关的描述气泡的左边距设置为链接的clientWidth的长度。但是,当我添加"绝对" css属性链接,他们搞砸了。 链接应该如何,但不是泡沫: how the links should be, but not the bubble 泡沫应该如何,但不是链接 how the bubble should be but not the links所以这是我的JavaScript函数

function hover(x){
var id = x;
var hoverBubble = document.getElementById(id);
var concat = ["menuLink", id];
var menuId = concat.join("");
var link = document.getElementById(menuId);
var linkWidth = link.clientWidth + 1;
hoverBubble.style.display = "inline";
hoverBubble.style.marginLeft = linkWidth + 'px';
}

1 个答案:

答案 0 :(得分:0)

还有其他方法可以“启用”clientWidth,例如float:leftdisplay:inline-block
这有帮助吗?