HTML: Top and Bottom v-align in same container

只谈情不闲聊 提交于 2019-12-11 06:48:12

问题


Given this little piece.

http://jsfiddle.net/4gb6K/7/

I am attempting to align the "bot" element at the bottom while keeping the "top" at top. I choose to draw up this little example with div's to try a few things my self, so ill use that instead of the actual one, same concept though.

Actual html looks more like:

    <a class="box" href="single.html" title="Link to Single Page">
        <h4>Cras vestibulum</h4>
        <p>Cras vestibulum lorem et dui mollis sed posuere leo semper.</p>
        <img alt="" src="images/box_ph.png">
    </a>

A is the container, H4 and P needs to v-align at top. where I would like to v-align image at bottom.

Any ideas? As vertical-align: bottom; doesn't do the trick, not sure if that is because it is in the same container as a top aligned element? But I don't have many ideas other than wrapping it all in huge amounts of HTML/CSS or going with fixed heights (currently it is actually "min-height" instead of "height" and absolute placements.


回答1:


Like this: jsFiddle example.

Use positioning on all three elements. Relative on the container, and absolute on the inner divs.

CSS:

.outer {
    height: 600px;
    border: 1px solid black;
    position: relative;
}
.top{
    position: absolute;
    border: 1px solid black;
    top: 0;
}
.bot{
    border: 1px solid black;
    position:absolute;
    bottom:0;
}

Update: Here's a jsFiddle example using your other code example with the appropriate CSS.



来源:https://stackoverflow.com/questions/9728159/html-top-and-bottom-v-align-in-same-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!