不能正确地定位标题Div

时间:2013-08-07 05:11:09

标签: css css3

请你看一下JSfiddle,让我知道如何使用.caption在div的底部放置div .wrapper

我已尝试将position:absolute; bottom:5px;规则添加到.caption,但它将标题div定位在.wrapper之外!

<div class="wrapper">
 <div class="caption">Test</div>
 <div class="main"></div>
</div>

这是css规则

.wrapper{
height:300px;
width:300px;
background-color:yellow;
}
.main{
height:100%;
width:100%;
}
.caption{
height:10%;
width:100%;
background: rgb(0, 0, 0) ; opacity: 0.7;>
margin-bottom:5px;
color:white;
}

3 个答案:

答案 0 :(得分:2)

position: absolute应该有效,但您需要将.wrapper设置为:

.wrapper {
   position: relative;
}

在这里演示:http://jsfiddle.net/sBxP2/4/

答案 1 :(得分:0)

试试这个

http://jsfiddle.net/shall1987/MwJsG/

CSS

.wrapper{
    height:300px;
    width:300px;
    background-color:yellow;
    position: relative;
}
.main{
    height:100%;
    width:100%;

}
.caption{
    height:10%;
    width:100%;
   background: rgb(0, 0, 0) ; opacity: 0.7;>
    margin-bottom:5px;
    color:white;
    position: absolute;    
    bottom: 0;
}

答案 2 :(得分:0)

你可以像这样更新你的CSS http://jsfiddle.net/shall1987/MwJsG/

.wrapper{
    height:300px;
    width:300px;
    background-color:yellow;
    position:relative;
}
.main{
    height:100%;
    width:100%;

}
.caption{
    height:10%;
    width:100%;
   background: rgb(0, 0, 0) ; opacity: 0.7;
    margin-bottom:5px;
    color:white;
    position:absolute;
    bottom:0;
}