可有人告诉我如何得到top和left位置的div或者span当没有指定的元素吗?
即:
<span id='11a' style='top:55px;' onmouseover="GetPos(this);">stuff</span>
<span id='12a' onmouseover="GetPos(this);">stuff</span>
Run Code Online (Sandbox Code Playgroud)
在上面,如果我这样做:
document.getElementById('11a').style.top
Run Code Online (Sandbox Code Playgroud)
55px返回值.但是,如果我尝试span'12a',那么什么都不会返回.
我在页面上有一堆div/ span我无法指定top/ left属性,但我需要div直接在该元素下显示.
我在搜索中看到过这样的一些问题,但要么问题没有得到正确回答,要么没有回答.所以,我会再问一次.
<style>
.parent { overflow-y:scroll; overflow-x:visible; width:100px; }
.child { position:relative; }
.child-menu { position:absolute; top:0px; left:-100px; display:inline-block; }
</style>
<div class="parent">
<!-- Lots of the following divs -->
<div class="child">
Text Line
<div class="child-menu">some pop out stuff</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
好吧,这只是一个例子.但基本上,我想要完成的是.child类可以在y轴上滚动...向上和向下滚动.但我想要x轴......子菜单在.parent容器外可见.
那有意义吗?所以发生的事情是,当页面呈现时,浏览器将溢出解释为完全自动而不尊重单独的轴.我做错了什么或浏览器还没有达到CSS3规范呢?大部分只在Chrome上测试过.