简体   繁体   English

图像和文本在中间不对齐?

[英]image and text not aligning in the middle?

I am trying to image and text in middle. 我正在尝试在中间图像和文字。

  <div class="topHeader">
    <img src="Images/loginheader.jpg" />
    <span> Sample text</span>                        
  </div>

div.topHeader {
   height:70px;
   background-color:#868686;
   font-family: Segoe UI;
   font-size:40px;
   padding-left:30px;
}

JSFiddle 的jsfiddle

Apply 应用

display:table; to your container and display:table-cell; vertical-align:middle; 到您的容器并display:table-cell; vertical-align:middle; display:table-cell; vertical-align:middle; to the span. 到跨度。

check this: FIDDLE 检查一下: FIDDLE

Add img{float:left} and div.topHeader{line-height:70px} . 添加img{float:left}div.topHeader{line-height:70px}

In fact, using line-height equal to the height of your div will center a one-lined text (and the image) vertically. 实际上,使用等于您的div高度的line-height将使line-height文本(和图像)垂直居中。 Just don't forget to make your image to float in order to write text in the same line as the image. 只是不要忘记使图像浮动以在与图像相同的行中写入文本。 A Fiddle. 小提琴。

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

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