Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6380043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:12:59+00:00 2026-05-25T02:12:59+00:00

I have a simple HTML button which contains text and an image: HTML: (Already

  • 0

I have a simple HTML button which contains text and an image:

HTML: (Already on http://jsfiddle.net/EFwgN)

<span class="Button">
    <img src="http://www.connectedtext.com/Image/ok.gif" />
    Small Icon
</span>

CSS:

span.Button {display:inline-block; margin:2px 4px;padding:3px 6px;
             background-color:#ddd; height:24px; line-height:24px;
             vertical-align:middle;}
span.Button img {vertical-align:middle;}

I can’t come up with a combination that would fit these requirements:

  • The image and text need to be vertically at the middle of the div, with the text in the middle of the image. It should be neat.
  • Horizontally – the image may be in any width, and the button should grow to show it.
  • Vertically – the image may be in any height, smaller or larger than the button. When the image is larger, I don’t mind if the extra pixels are displayed or cropped, as long as it is centered.
  • The button is in a fixed height. Currently I use line-height to center the text.
  • The button should sit nicely in line with other buttons and text.
  • The solution needs to work on all latest versions of major browsers, and Internet Explorer 8.

Here’s a jsfiddle with my current code: http://jsfiddle.net/EFwgN
(note the small icon is slightly below the center of the button)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:12:59+00:00Added an answer on May 25, 2026 at 2:12 am

    A simple solution, if you need no less than IE8 (in Standards mode): http://jsfiddle.net/kizu/EFwgN/31/

    Just add margin: -100px 0 to img, so the negative margin would eat any large height:

    span.Button img {vertical-align:middle; margin:-100px 0;
                     position:relative; top:-2px;}
    

    I’ve added position: relative; top:-2px; just to look it better 🙂

    But if you’ll need support for compatibility mode or IE lt 8 (for some reason), the thing with margin won’t work. So you’ll need an extra markup: http://jsfiddle.net/kizu/EFwgN/28/, but it’s somewhat hacky and works only with the fixed button’s height (like in your example).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple html, a div which contains some html and a delete
I have a simple Jquery dialog box, that dialog contains a button which sends
I have a site that has a simple HTML button in a form. All
This is probably a basic html/css question... I have a simple one-button form that
I have a simple html block like: <span id=replies>8</span> Using jquery I'm trying to
I have a simple WCF service application which contains a list of room items
I have an HTML page which contains an Object tag to host an embedded
I have a custom model class which contains a decimal member and a view
I have simple html with div and button . Also i have a css
I have a simple html application which displays words on a click of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.