Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
xiaowei zhu
Courses Plus Student 1,425 PointsVertical Align middle a icon in button
i want Vertical Align middle a image icon in button
this is my html.
<button>
<i class="i-book"></i>text
</button>
hope it can behave like font icon. Does anyone know how to do this?
2 Answers
Cosmin Cioaclă
21,339 PointsYou can try removing the height from the button element and use equal top and bottom padding instead.
xiaowei zhu
Courses Plus Student 1,425 Points@Cosmin Cioaclă i hope i can just use line-height to do this. but it cant. your solution is a way. but if i use different size icon, i must ajust padding every time.
Cosmin Cioaclă
21,339 PointsWhy would you have to adjust the padding? As long as you set your top padding equal to your bottom padding, you should always have a vertical aligned icon, regardless of the size of it.
xiaowei zhu
Courses Plus Student 1,425 Points@Cosmin Cioaclă but the button height will change. if i want keep the height, i must adjust the padding to fit.
xiaowei zhu
Courses Plus Student 1,425 Points@Cosmin Cioaclă but the button height will change. if i want keep the height, i must adjust the padding to fit.
Cosmin Cioaclă
21,339 PointsYou can also use percentages for padding, maybe that can be of help. The percentage value refers to the width of the containing block. More info here.