好的。因此,要获得 clientWidth,您必须添加代码
#menuSystem a{
position: absolute;
height: auto;
width: auto;
font-size: 15px;
}
您需要执行此操作才能使其有资格确定客户端宽度。我想要做的是将与链接相关的描述气泡的左边距设置为链接的 clientWidth 的长度。但是,当我将“绝对”CSS 属性添加到链接时,它们会变得一团糟。链接应该如何,而不是气泡: 气泡应该如何而不是链接 所以这是我的 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';
}
还有其他方法可以“启用”clientWidth
,例如float:left
或display:inline-block
。
有帮助吗?
我是一名优秀的程序员,十分优秀!