Description of two implementation methods for aligning CSS icons and text

高洛峰
Release: 2017-03-09 10:15:04
Original
2195 people have browsed it

In the process of writing pages, we often encounter the situation of aligning small icons with text. For example:

Summarizes the two methods, the amount of code is relatively Less. Description of two implementation methods for aligning CSS icons and text

The first one

  Set the vertical alignment of img to middle,

<p>
        <img src="" alt="" class="heart">
        <span>1169</span>
        <img src="" alt="" class="comment">
        <span>1168</span>
</p>
Copy after login
p{    
     height:30px;    
     line-hight:30px;    
}    
.heart,.comment{    
        vertical-align:middle;    
}
Copy after login


##The second type

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

<p>
        <span class="heart">1169</span>
        <span class="comment">1168</span>
</p>
Copy after login


.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;    
}
Copy after login


The above two methods for realizing the alignment of css icons and text are all the content shared by the editor. I hope it can give you a reference. I also hope that everyone will support the PHP Chinese website.

The above is the detailed content of Description of two implementation methods for aligning CSS icons and text. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template