【问题标题】:Understanding relative and absolute positioning: how to align an internal div to the bottom of the container了解相对定位和绝对定位:如何将内部 div 与容器底部对齐
【发布时间】:2012-01-14 13:14:46
【问题描述】:

仍在学习如何使用 div 和 css 进行布局。我有以下html:

<div id="Fascione">
</div>
<div id="Wrapper">
    <div id="Menu">
    </div>
    <div id="Contenuto">
        <div id="Liturgia">
        </div>
        <div id="Container">
            <div id="Ristorante">
            </div>
            <div id="Insieme">
            </div>
            <div id="Progetto">
            </div>
        </div>
        <div id="Unitre">
        </div>
    </div>
</div>
<div id="Footer">
</div>

css 看起来像:

html, body{width:100%;height:100%;}
body{width:1024px; margin:0px auto;padding:0px;border-width:0px;}
div#Fascione{width:inherit;height:125px;border-bottom:2px solid black;}
div#Wrapper{width:inherit;padding:8px 0px 8px 0px;/*background-color:#647;*/}
    div#Menu{float:left;width:200px;/*background-color:#F41;*/}
    div#Contenuto{margin-left:208px;/*background-color:#9bb;*/}
         div#Liturgia{float:left;width:34%;margin-bottom:1%;background-color:#987;}
         div#Container{float:left;width:65%;margin-bottom:1%;margin-left:1%;background-color:#aaaaaa;}
            div#Ristorante{float:left;width:49%;margin-bottom:1%;margin-left:1%;background-color:#123;}
            div#Insieme{float:left;width:49%;margin-bottom:1%;margin-left:1%;background-color:#abc;}
            div#Progetto{float:left;border-top:1px solid gray;background-color:#369;}
     div#Unitre{clear:left;border-top:1px solid gray;background-color:#de7;}
div#Footer{clear:left;width:inherit;height:40px;border-top:2px solid black;/*background-color:#1a9;*/} /* clear left needed! */

我想做的是让“Progetto”div 底部边框与“Unitre”顶部边框粘在一起。

阅读其他帖子我尝试将“Container”设置为 position:relative,将“Progetto”设置为 position:absolute;bottom:0px;但这并不能满足我的需要。

谁能帮帮我?

【问题讨论】:

  • 我编辑了我的 css,因为我留下了一些我确实没有使用的“相对位置”,我忘记添加一些我为 body 和 html 定义的样式

标签: html css layout


【解决方案1】:

使用相对位置设置容器不是一个好习惯。您应该尝试将两个 div 之间的边距清零,并且只在所需的边添加边框,例如:

    Proggetto{
//no bottom border;
border:1px 1px 0 1px;
border-color:black;
margin:0;
}
Unitre{
border:1px solid black
margin:0;
}

【讨论】:

  • 我认为我在 css 中的错误在这里造成了误解。我尝试了您的建议,但没有解决我的要求。我现在编辑了我的帖子,它更清楚了。还是谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-21
  • 1970-01-01
  • 1970-01-01
  • 2020-03-10
  • 1970-01-01
  • 2010-10-09
相关资源
最近更新 更多