简体   繁体   English

在图标旁边对齐文本

[英]Aligning text next to icons

So I'm trying to align these images next to each other but I'm having trouble doing so. 因此,我试图将这些图像彼此对齐,但是这样做很麻烦。

I tried a vertical-align however wasn't successful at it! 我尝试了垂直对齐,但是没有成功!

HTML: HTML:

<ul class="ex-links">
    <li><i class="fa fa-users"></i><a href="">About Us</a></li>
    <li><i class="fa fa-flag"></i><a href="">Events</a></li>
    <li><i class="fa fa-picture-o"></i><a href="">Gallery</a></li>
    <li><i class="fa fa-question-circle"></i><a href="">FAQ's</a></li>
    <li><i class="fa fa-archive"></i><a href="">Archive</a></li>
</ul>

CSS: CSS:

   .explore-links {
        margin-right: 15px;
    }

    .ex-links {
        padding: 5px;
    }

    .ex-links li {
        font-size: 16px;
        padding-bottom: 8px;
    }

What it shows: 显示内容:

https://sc-cdn.scaleengine.net/i/b3f6ef6e0d5b72b1ca363fff8a02e78f.png

Basically, I'm simply trying to align the text next to the image (Which it shows) but they all go in and out down the line. 基本上,我只是在尝试将图像旁边的文本对齐(如图所示),但是它们都沿线进出。 The sizing of the icons are why it's doing that, so I was wondering how I'd go about tackling the CSS to where it all aligns perfect, rather than indenting for every li row based on the icon. 图标的大小是为什么它这样做,所以我想知道我怎么会去解决的CSS到这一切完美对齐,而不是缩进为每li基于图标的行。

Fiddle 小提琴

thanks! 谢谢!

My go to method for vertical aligning is using the followng styles: 我的垂直对齐方法是使用以下样式:

.v-aligned-parent{
    position:relative;//Or absolute, just not static;
}
.v-aligned{
    position: absolute;
    top:50%;
    left: 0%;
    transform:translate(0%, -50%);
    -webkit-transform:translate(0%, -50%);
}

As applied to your fiddle (note i also tweaked some paddings): 适用于您的小提琴(请注意,我还调整了一些填充):

https://jsfiddle.net/d5xgfkn8/ https://jsfiddle.net/d5xgfkn8/

You can use display properties table , table-row and table-cell 您可以使用显示属性tabletable-rowtable-cell

ul {
    display: table;
}
li{
    display: table-row;
}
i, a{
    display: table-cell;

}
a{

    padding-left: 10px;
}

Checkout this DEMO 签出此演示

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

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