简体   繁体   中英

How to pad the text in a span, but not pad the background image

I have a situation where I have a SPAN with a background image of a button, with text. The text is however on top of the button, while I want it to be vertically centered. I tried to adjust it with padding, but then the background image shifts along...

The html code:

<span class="button" style="BACKGROUND-IMAGE: url('images/button.gif'); HEIGHT: 50px; PADDING: 15px 10px 0px 0px; WIDTH: 50px">button text</span>

Thanks in advance, I have the feeling that I am overlooking something simple...

Add this to your CSS:

line-height: 50px;
display: inline-block;
padding: 0 10px;

You may need to adjust your padding, but setting the line height to the height of the button itself will center its content vertically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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