简体   繁体   English

文字在li内垂直对齐

[英]Text align vertical within li

<ul id = "Software">
   <li id = "pdf1"> <img src="/Content/img/pdf.png">Catalogue</li>
   <li id = "pdf2"> <img src="/Content/img/pdf.png">Manual Data</li>
   <li id = "pdf3"> <img src="/Content/img/pdf.png">Technical Data</li>
   <li id = "software1">Software</li>
</ul>

The text in the list elements is appearing at the bottom. 列表元素中的文本显示在底部。 How to center it alongside the image? 如何将其与图像对齐?

li img { vertical-align: middle; }

Demo jsBin 演示jsBin

  ul li{
    list-style:none;
    display:inline-block;
    height:40px;
    line-height:40px;
  }
  li img{
    float:left;
    margin:5px;
  }

You need to set a height and same line-height for your li element; 您需要为li元素设置一个height和相同的line-height
for the containing images - set float : left 对于包含的图像-设置float : left

Set the same height and line-height . 设置相同的heightline-height This will do the trick. 这将达到目的。

要对齐文本和图像,可以在图像元素上使用margin-bottom:-5px ,数字取决于图像的大小。

I think you are looking for vertical-align . 我认为您正在寻找vertical-align

http://www.w3schools.com/cssref/pr_pos_vertical-align.asp http://www.w3schools.com/cssref/pr_pos_vertical-align.asp

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

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