F21*_*F21 7 html css positioning alignment
我有一个包含2段的div.我希望段落与div的右下角对齐.我能够使用这些参数来对齐text-align: right,但是我正在努力让这些参数与div的底部对齐.
标记很简单:
<div>
<p>content 1</p>
<p>content 2</p>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
div{
border: 1px red solid;
height: 100px;
}
p{
text-align: right;
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用position:absoluteparagrams和设置bottom: 0,但这使得段落由于绝对定位而相互重叠.
div不会跨越整个页面,因此段落文本应该在div中.
有没有办法实现这样的效果,使内容"从底部增长"?
我想要的效果是这样的(photoshopped):

以及上面的小提琴:http://jsfiddle.net/cbY6h/
Bil*_*ill 20
HTML
<div class="box">
<div class="content">
<p>content 1</p>
<p>content 2</p>
</div>
</div>?????????????????????
Run Code Online (Sandbox Code Playgroud)
CSS
.box {
border: 1px red solid;
height: 100px;
position: relative;
}
.content {
position: absolute;
bottom: 0;
right: 0;
}
Run Code Online (Sandbox Code Playgroud)
将内容放在div的右下角.您可以在http://jsfiddle.net/cbY6h/1/上看到结果.
我正在寻找类似的东西,最终使用了 flexbox 布局。
鉴于以下结构
<div>
<p>content 1</p>
<p>another</p>
<p>content 2</p>
</div>
Run Code Online (Sandbox Code Playgroud)
还有这种风格
div {
border: 1px red solid;
height: 100px;
display: flex;
//align items from top to bottom
//[I've always thought the opposite, as rows are counted from top to bottom
//and columns are counted left to right. Any one have an explanation for this?]
flex-direction: column;
//main axis align to the bottom, since we are using column for direction
justify-content: flex-end;
}
p {
//cross axis align towards the right. total outcome => bottom right
align-self: flex-end;
}
Run Code Online (Sandbox Code Playgroud)
您将从图片中获得布局。
编辑:不适用于旧版浏览器 ( http://caniuse.com/flexbox )。您可以使用 Modernizer
.flexbox .rest-of-your-selector { rule }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
36083 次 |
| 最近记录: |