简体   繁体   English

CSS,为什么这些div彼此叠放?

[英]CSS, why are these div's piling on top of each other?

Basicly I would like these 4 buttons to seperate with a width of 5px between them? 基本上我希望这4个按钮分开,它们之间的宽度为5px? When I had my position as relative it worked fine but when I put it to absolute they each pile on top of each other? 当我担任亲戚时,它运作良好,但是当我把它放到绝对位置时,它们彼此叠在一起吗? Why is this and does anyone know a fix? 为什么会这样,有人知道解决方法吗? Thanks. 谢谢。

Code: 码:

#content
{
    position: absolute;
    top: 220px;
    left: 505px;
    width: 860;
    height: 560px;
}

#content ul li
{
    text-decoration: none;
    position: absolute;
    margin-right: 2px;
    font-family: "Arial Black";
    padding: 10px;
    width: 180px;
    text-shadow: 1px 1px 1px #000;
    text-align: center;
    background-color: #000;
    opacity: 0.5;
    display: block;
}

Example (Buttons in the top left.): 示例(左上角的按钮。): 在此处输入图片说明

From the MDN page on positioning : MDN页面上的定位

Elements that are positioned relatively are still considered to be in the normal flow of elements in the document. 相对放置的元素仍被认为是文档中元素的正常流动。 In contrast, an element that is positioned absolutely is taken out of the flow and thus takes up no space when placing other elements. 相反,绝对定位的元件从流中取出,因此在放置其他元件时不占用空间。 The absolutely positioned element is positioned relative to nearest positioned ancestor. 绝对定位的元素相对于最近定位的祖先定位。 If a positioned ancestor doesn't exist, the initial container is used. 如果不存在已定位的祖先,则使用初始容器。

They are piling up on top of each other because no space is reserved for them in the flow of the page. 它们在彼此之上堆积,因为在页面流中没有为它们保留空间。

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

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