简体   繁体   English

如何获取文本以对齐图片?

[英]How do I get my text to align my picture?

This is the look: 外观如下:

在此处输入图片说明

How do I move the text up? 如何上移文字? So its centered besides the image? 所以它除了图像之外居中?

CSS: CSS:

header{
padding: 20px;
background-color: #34495e;
color: black;
}
.header-1{
 color: white;
padding: 0px 190px;
font-size: 17px;
vertical-align: middle;
line-height: 20px;
}
.logopng{
width: 35px;
height: 35px;
}

HTML: HTML:

 <header>
 <div class="header-1">
 <img src="http://i.imgur.com/cGlBmw7.png" class="logopng">
 Rocket League Prices
 </div>
 </header>

EDIT: added vertical-align:middle to the image class 编辑:向图像类添加了vertical-align:middle

The easiest way is to set display: flex and align-items: center on parent element. 最简单的方法是设置display: flexalign-items: center以父元素为align-items: center

 header { padding: 20px; background-color: #34495e; color: black; } .header-1 { color: white; font-size: 17px; display: flex; align-items: center; } .logopng { width: 35px; height: 35px; margin-right: 20px; } 
 <header> <div class="header-1"> <img src="http://i.imgur.com/cGlBmw7.png" class="logopng">Rocket League Prices </div> </header> 

you can use css3 flexbox concept.just add 您可以使用css3 flexbox concept.just添加

display:flex;
align-items:center;
justify-content:center;

to your .header-1 it works fine.I'm added the snippet below. 到您的.header-1 ,效果很好。我在下面添加了代码段。

 header{ padding: 20px; background-color: #34495e; color: black; } .header-1{ color: white; font-size: 17px; display:flex; align-items:center; justify-content:center; } .logopng{ width: 35px; height: 35px; margin-right:10px; } 
 <header> <div class="header-1"> <img src="http://i.imgur.com/cGlBmw7.png" class="logopng"> Rocket League Prices </div> </header> 

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

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