简体   繁体   English

CSS将h1元素与流体标题中的图像底部对齐

[英]CSS align an h1 element with the bottom of an image in fluid header

I have a header element that with a css width of 80%. 我有一个标头元素,其CSS宽度为80%。 Inside that element I have an image which I want to be positioned on the left of the header, a logo, and I have an h1 element I want positioned on the right of the header, a tagline, as follows: 在该元素内部,我有一个图像想要放置在标题的左侧,一个徽标,并且我有一个h1元素我想要放置在标题的右侧,一个标语,如下所示:

10% ---| {LOGO} {TAGLINE} |--- 10%

My problem is this, the image has a height of around 65px and the h1 has a text height of about 20px, I want them to be aligned perfectly at the bottom so that the bottom of the text is flush with the bottom of the image. 我的问题是,图像的高度大约为65px,h1的文本高度大约为20px,我希望它们在底部完全对齐,以便文本的底部与图像的底部齐平。

I know I could use line height and work out the difference, or I could absolute position them and give them a css "bottom" attribute, but is there a smarter way? 我知道我可以使用线高来计算出差异,或者我可以绝对定位它们并为它们提供一个CSS的“底部”属性,但是有没有更聪明的方法?

This should work: 这应该工作:

HTML HTML

<header>
    <img src="http://placehold.it/200x65" alt="" />
    <h1>Tagline goes here</h1>
</header>

CSS CSS

header {
    background: #eee;
    width: 80%;
    text-align: center;
}
header > * {
    display: inline-block;
    vertical-align: bottom;
}
header h1 {
    font-size: 20px;
    line-height: 1;
    margin: 0;
}

JSFiddle for example: http://jsfiddle.net/galengidman/9309yrL6/1/ 以JSFiddle为例: http : //jsfiddle.net/galengidman/9309yrL6/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM