Home  >  Article  >  Web Front-end  >  How to make icons and text appear vertically centered using css sprites_html/css_WEB-ITnose

How to make icons and text appear vertically centered using css sprites_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:11:571293browse

I’m writing a blog interface
Originally, it didn’t matter if I used sprites or not. It’s a small website.
But I’ve never used sprites before, so I wrote about it today
But I didn’t use sprites before. After inserting icons, pictures and text directly You can center it vertically by using the same height as height and line-height
After using sprites, because the background is inserted, the vertical centering is difficult to control
I don’t know if you have any good methods. Can you recommend it


Reply to discussion (solution)

The original poster should center the container vertically
or
background:url(...) center;
like this?

HTML:

Blog Search


CSS:
.iconA {display :inline-block; height:16px; width:16px; background:url(icons.png) -20px -20px no-repeat}

allows the icon and text to be displayed on the same line and the icon will not be a little higher

iconA
Add
vertical-align:middle;
Try

Solved
vertical-align:middle; It will still be a little misaligned
Use margin-bottom to adjust it to a negative value and it will be OK
Thanks

Statement:
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