简体   繁体   English

将左对齐文本与右对齐图像垂直对齐

[英]vertically align left aligned text with right aligned image

I'm designing a liquid layout mobile website. 我正在设计一个流动的布局移动网站。 As the header I have a centered div that that has "text-align: right;", which contains my logo. 作为标题我有一个居中的div,它有“text-align:right;”,其中包含我的徽标。 Then an other div is set to "float: left;" 然后另一个div设置为“float:left;” and this one contains my site title. 这个包含我的网站标题。

I wish to vertically align the text to the logo, while the text remains aligned to the left, and the logo stays aligned to the right, how do I accomplish this? 我希望将文本垂直对齐到徽标,同时文本保持与左侧对齐,徽标保持与右侧对齐,我该如何实现?

Stripped code for the relevant bit: 相关位的剥离代码:

<div id="wrapper">

<div id="title">
    <h3>My title</h3>
</div><!--end title-->

<div id="logo">
    <img src="images/logo.jpg" alt="Logo" class="logo" />
</div><!--end logo-->

CSS: CSS:

html, body{
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: Arial, Helvetica, sans-serif;
}
img.logo{
    width: 96px;
    height: 41px;

}

#wrapper{
    min-height: 100%;
}

#title{
    float: left;
    padding: 0.5em 0 0.5em 10%;
}

#logo{
    width: 90%;
    margin: 0 auto;
    text-align: right;
    padding: 0.5em;
}

Many thanks in advance! 提前谢谢了!

You can use text-align: justify like so: 您可以像这样使用text-align: justify

 div { text-align: justify; line-height: 100px; height: 100px; background: gold; } img, span { display: inline-block; vertical-align: middle; } div:after { content: ''; display: inline-block; width: 100%; } 
 <div> <span>test</span> <img src=http://placehold.it/100x50> </div> 

Demo on Codepen Codepen上的演示

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

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