html - 了解相对和绝对定位 : how to align an internal div to the bottom of the container

标签 html css layout

仍在学习如何使用 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;但这并不能满足我的需要。

谁能帮帮我?

最佳答案

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

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

关于html - 了解相对和绝对定位 : how to align an internal div to the bottom of the container,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8862431/

相关文章:

javascript - IE 中的选项卡顺序问题与表单中字段的初始 Javascript 选择

jquery - 我可以使图像随着内容 div 扩展而不会扭曲吗

html - 如何在 CSS 中更改图像背景位置?

android - 结合 Canvas 和布局 (Android)

html - 如何对齐伪元素:before :after and span element

javascript - 在移动设备上更改基于滚动的淡入淡出?

javascript - HTML 输入类型数字 min 和 max 属性在 IE 中不起作用

具有后退按钮兼容性的 jQuery 侧面板

html - 如何使用html div标签和css进行水平分割

安卓布局 : cannot see the children over the parent