简体   繁体   English

绝对和相对div定位

[英]absolute and relative div positioning

I have created a few divs inside divs:). 我在div内创建了一些div :)。 The problem is that the FOOTER div is printed above the div which contains absolute divs and is not dipalyed as last (at the bottom). 问题是FOOTER div是在包含绝对div的div上方打印的,并且最后没有被二元化(在底部)。

I tried a few combinations for footer div like: "position: absolute; top: 0px; left:0px" , but it still displyed at the top of page. 我为页脚div尝试了几种组合,例如: "position: absolute; top: 0px; left:0px" ,但它仍显示在页面顶部。

How to move it to the bottom with current divs? 如何将当前div移到底部? http://jsfiddle.net/hsbgpmus/2/ http://jsfiddle.net/hsbgpmus/2/

Where is the problem? 问题出在哪儿?

ADDED: 添加:

I want to have footer div not at the bottom of web browser window, but as last div right after div containing BBBB string. 我希望页脚div不在Web浏览器窗口的底部,而是在包含BBBB字符串的div之后的最后一个div。

try this 尝试这个

<div style="position:relative; height:600px">
<div style="width: 100px">
    <h1>HEaDER</h1>
    <div>
        <div style="position: static">
            <div style="padding: 10px; position: absolute; top: 100px; left: 100px; background-color: yellow;">aaaaa</div>
            <div style="padding: 10px; position: absolute; top: 200px; background-color: yellow;">cccc</div>
            <div style="padding: 10px; position: absolute; top: 300px;  background-color: yellow;">bbbb</div>
        </div>
        <div style="position: absolute; bottom:0">
            <h1>FOOTER</h1>
        </DIV>
    </div>

http://jsfiddle.net/anjum121/xmox7pjq/ http://jsfiddle.net/anjum121/xmox7pjq/

you need to wrapp your parent div to relative position 您需要将父div包装到相对位置

You have used "position:static" in your example fiddle. 您在示例小提琴中使用了“ position:static” Static means the element will flow into the page as it normally would. 静态意味着元素将像往常一样流入页面。

For more info. 有关更多信息。 about positioning element using css refer this link . 有关使用CSS定位元素的信息,请参考此链接

Positioning element absolutely and setting top and left to 0px means you want to align it at the top. 绝对定位元素并将顶部和左侧设置为0px表示您想将其顶部对齐。 To align element at the bottom of the parent element, you have to set bottom property (not top property) 要将元素在父元素的底部对齐,您必须设置bottom属性(而不是top属性)

CSS code : CSS代码:

<footer_element_class_or_id> {
    position: absolute;
    bottom: 0px;
    left: 0px;
}

Hope it helps. 希望能帮助到你。

将以下代码用作页脚,

position: absolute; bottom: 0px; left:0px

try this fiddle 试试这个小提琴

http://jsfiddle.net/hsbgpmus/3/ http://jsfiddle.net/hsbgpmus/3/

.footer{

    position:absolute;
    bottom:0;

}

html HTML

<div class ="footer"><h1>FOOTER</h1></DIV>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM