CSS: Two ways to align icons with text

Source: Internet
Author: User

(Long time no blog, the accumulation of these months is more fragmented, recorded in the book, and now began to organize classification)

In the normal process of writing a page, often encountered in order to put small icons and text to align the situation. Like what:

Summed up two methods, the code is relatively small amount.

First KindSet the vertical alignment to middle for the img,
<div>                <span>1169</span>                <span>1168</span></div>

div{     height:30px;     line-hight:30px;}.heart,.comment{        Vertical-align:middle;}    

The second Kind

    Set the small icon as the background image, adjust the padding

<div>        <span class= "Heart" >1169</span>        <span class= "comment" >1168</span> </div>

. hear{        Background:url (images/heart.png) left center no-repeat;        margin-right:20px;}. comment{        Background:url (images/comment.png) left center no-repeat;}.hear,.comment{        height:30px;        line-height:30px;        padding-left:20px;}

    

CSS: Two ways to align icons with text

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.