CSS嵌套Div与位置绝对? [英] CSS nested Div with position absolute?
问题描述
这里是一个更复杂的情况的复制:
Here is a reproduction of a far more complex case:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<div style="position:absolute;left:500px;top:200px;width:200px;background-color:red;";>
AS HDSKLAJD KLASJD KLASJ DKLASJDKL JASKLD JKLAS JDKLASD AS HDSLAJD
<p>
sadas dasd sad asd sadas dasd sad asdsadas dasd sad asdsadas dasd sad asd
</p>
<div style="position:absolute;left:0;top:0;width:10px;background-color:green;";>
CORNER
</div>
</div>
</body>
</html>
我想要的是将CORNER文本的div放在页面的0,0处。我知道我可以简单地更改DIV在html中是在绝对的第一个DIV,但我不能这样做,因为在实际情况下,我限制为一个ContentPlaceHolder(ASP.NET)。所以,有可能有一个DIV嵌套在其他DIV里的位置绝对和坐标绝对于页面?
What I want is to have the div with the CORNER text at the 0,0 of the page. I KNOW I can simply change the DIV in the html to be outside the first DIV with absolute but I cannot do it since in the real case I am limited to a ContentPlaceHolder (ASP.NET). So, is it possible to have a DIV that is nested inside an other DIV with position absolute and to have its coordinate absolute to the page?
推荐答案
那么,是否有可能有一个DIV嵌套在一个位置绝对的其他DIV中,并且其坐标绝对于页面?
So, is it possible to have a DIV that is nested inside an other DIV with position absolute and to have its coordinate absolute to the page?
不是绝对的页面,不。您可以使用负值 left
和 top
值将DIV移动到容器外 - 如果左边
和顶部
坐标是固定的,你可以实现这种方式的效果 - 但是坐标总是相对于容器,
Not absolute to the page, no. You can use negative left
and top
values to move the DIV outside the container - if the left
and top
coordinates of the container are fixed, you can achieve the effect that way - but the coordinates will always be relative to the container, never to the page.
编辑: position:fixed
突破容器(尝试在您的示例中更改它, left:0px top:0px
会将其放置在页面的左上角它),但它有固定在视口,而不是在文档中的明显的副作用 - 所以它只有在没有滚动发生在身体有用。
There's position:fixed
that does break out of the container (try changing it in your example, left: 0px top: 0px
will place it in the top left corner of the page as you want it) but it has the obvious side-effect of being fixed on the viewport, not in the document - so it's useful only if no scrolling occurs in the body.
这篇关于CSS嵌套Div与位置绝对?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!