获取高度以在绝对模式下定位 div
因为我的最后一个问题立即得到了回答..我决定发布一个新的问题,它把我所有的头发都带走了,XD
这就是问题..
我有一个带有绝对定位div的设计..它有一个透明的png和一个简单的锚……就这样。
<div class="buyfloat">
<img src="img/buy.png" />
</div>
所以..我需要这个div.buyfloat定位在一个绝对位置...不移动..没有跳跃没有褪色..我只需要它在距离页面最底部200px的地方...因为我需要它就在页脚的顶部..随着页面高度的增加或减少..我无法使用顶部选择器。
好吧..“使用底部!” 你可能会说..是的,先生,我试过了..但是出于某种原因..底部选择器使用窗口高度(可见部分)而不是整个东西..并且..如果我向下滚动页面..图像是就在页面的中间。
.buyfloat{
width:333px;
height:135px;
position:absolute;
left:10px;
bottom:200px; /** not working **/
margin:5px auto 0 auto;
z-index:99;
}
我正在寻找一些JavaScript(我想我前段时间看到过一个),它可以让我在CSS上获得身体高度..但是如果你有任何不同的和更简单的解决方案..我洗耳恭听!
提前致谢。
as my last question was answered inmediatly.. i decided to post a new one which is taking all my hair away, XD
this is the problem..
i have a design with an absolute positioned div.. which has a transparent png and a simple anchor... just like this.
<div class="buyfloat">
<img src="img/buy.png" />
</div>
so.. i need this div.buyfloat positioned at an absolute position... not moving around.. no jumping no fading.. i just need it at 200px from the very bottom of the page... because i need it just on the top of my footer.. and as the heigh of the pages increases or decreases.. i can´t use top selector.
well.. "use bottom!" you may say.. yes sir i tried.. but for some kind of reason.. the bottom selector uses the window height (visible part) instead the whole thing.. and.. if i scroll the page down.. the image is right in the middle of the page.
.buyfloat{
width:333px;
height:135px;
position:absolute;
left:10px;
bottom:200px; /** not working **/
margin:5px auto 0 auto;
z-index:99;
}
i'm looking for some javascript (i think i saw one sometime ago) that gives me the body height right on the css.. but if you have any different and easier solution.. i'm all ears!
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请记住,“position:absolute”实际上是相对于位置值不是“static”的元素的第一个祖先(请参阅 http://www.w3.org/TR/CSS2/visudet.html#containing-block-details)。 所以也许您遇到这种情况,并且“底部”是从其他元素而不是 html/body 测量的。
Bear in mind that "position: absolute" is actually relative to the first ancestor of the element that has a position value other than "static" (see point 4 in http://www.w3.org/TR/CSS2/visudet.html#containing-block-details). So maybe you have this situation and the "bottom" is measuring from some other element rather than html/body.
首先,JS 在 CSS 中工作的唯一方式是通过“表达式”,这仅适用于 IE,其次,这需要您的用户也打开 JS。
pos:abs 从正常布局中删除元素,并将其放置在最近的绝对或相对父元素上。 如果您使用严格或过渡的 xhtml,如果您也使正文相对,那么“底部”绝对可以工作:
First off, the only way JS works in CSS is via "expression" which is IE only, secondly this would require your users also had JS turned on.
pos:abs removes the element from normal layout and places it with respect to the nearest absolute or relative parent. If you're in strict or transitional xhtml, bottom will absolutely work if you just make the body relative too: