Is there a way to align text in the middle of a button vertically?

Why isn't the line-height property vertically center-aligning text in my button as expected?

In Firefox, Opera, and Safari, the text appears to be bottom-aligned.

Here is a link to my JSFiddle demonstration.

<button class="get_discount_rate">Button</button>
button {
  font-family: Arial, Helvetica, sans-serif;
  font-weight: normal;
  color: #444;
  min-width: 90px;
  height: 24px;
  line-height: 24px;
  margin: 5px 10px;
  background-color: #fdfdfd;
  border: 1px solid #cdcdcd;
  cursor: pointer;
  border-radius: 3px;
}

Answer №1

Centered text vertically within a button element (Tested and compatible with Chrome, Firefox, Safari, Opera, and IE8)

button {
    font-family: Arial, Helvetica, sans-serif;
    font-weight: normal;
    color: #444;
    min-width: 90px;
    padding:5px;
    margin: 5px 10px;
    background-color: #fdfdfd;
    border: 1px solid #cdcdcd;
    cursor: pointer;
    border-radius: 3px;
}​

Check out the DEMO here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

CSS active state not functioning properly

While working with asp.net4.0, I am attempting to create a menu bar using CSS. Everything seems to be working fine except for the 'active' code, which doesn't seem to be responding as expected. Any insights into why this might be happening? ...

Steps for making a toggle button with Bootstrap

Initially, I developed a web application using HTML, CSS, and JavaScript. Later on, I was requested to recreate it using Bootstrap as well. While I managed to complete the task successfully, I encountered an issue where toggle buttons in the web app revert ...

Show off a font-awesome icon overlapping another image

My task involves fetching image source from a JSON file and then displaying it on an HTML page. https://i.sstatic.net/coOaU.png I also need to overlay a Font Awesome icon on top of the image as shown below: https://i.sstatic.net/nbrLk.png https://i.sst ...

Encountering an issue while attempting to install an SSL certificate on my server. The error message displayed is: "ERROR:

Unique HTML Code: <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="farmapp.css"> </head> <body onload=&qu ...

Troubleshooting: Difficulty getting CSS `position: absolute` to correctly position a div above all other elements

In my current project, I am utilizing Javascript, specifically the VueJS framework, to create a page named mainTextEditor. This page consists of a text field and a 'popup' that is implemented using a div with a v-if directive to show the div when ...

Keep the footer firmly attached to the bottom of the page, even as the contents shift and change

Having an issue with my HTML pages where the footer is not sticking to the bottom when there is vertical scroll due to excessive content. Here is the basic layout of my pages: <body> <div id="container"> <div id="header"> Hea ...

I am looking to switch the content between two divs. Specifically, I want to take the content from div 1 and move it to div 2, while moving the

I am facing a challenge involving three divs. One of them is the main div, while the other two are positioned below it and contain different content. I am trying to find a way to swap the content between div one and div two in such a way that the original ...

Tips for customizing the toggle animation styling

I'm new to HTML and CSS, currently working on designing a website for our conference. I've implemented a toggle effect for displaying the information about invited speakers along with their research interests using the following code: <!DOCTY ...

Unable to load JavaScript in an HTML file

I have tried numerous solutions for my issue, but none seem to work. When testing in JSFiddle, the code works perfectly due to automatic onload support. However, when I open the same HTML file locally in Chrome/IE/FireFox, the layout is correct but the J ...

React: Modify the appearance of one component when hovering over another component

Currently, I am delving into the world of React and have come across a piece of code that successfully applies an opaque white overlay over an image when hovering over a button. This functionality is working as expected: class Product extends Component { ...

Is it possible to develop Hybrid Apps specifically for Windows Tablets/Surface devices?

We have created a Hybrid App for Android devices and made it compatible with Windows by using Adobe PhoneGap Build to generate a .XAP package from the existing Source Code. We believe that this .XAP package can easily be deployed on a Windows Mobile devic ...

What could be causing my custom cursor to malfunction?

I've been attempting to customize the cursor image, but despite following all provided instructions, it's still not working: CSS: body, html { margin: 0px; padding: 0px; border: 1px solid red; cursor: url(images/rsz_red_crosshair.gi ...

Activate div2 visibility upon hovering over div1 using jQuery

I have a shopping basket on my website, and I want to display a list of products when a user hovers over the basket icon. However, I am facing an issue where the list disappears as soon as the mouse leaves the basket logo. Is there a way to keep the list ...

Tips for centering text inside a div using a separator

During my side project, I decided to use the angular material divider but encountered issues with aligning the text correctly. https://i.stack.imgur.com/zg1mu.png The problem can be seen in the image provided - the text on the right side is not aligned b ...

Create custom sign board buttons using CSS styling

Check out the button design linked below: I attempted to recreate this design using before and after, but I want the arrow to be softer. I tried skewing it as well. I also searched for references, but couldn't find similar examples online even though ...

What is the best way to create divs with no gaps in between them?

I am trying to create a div structure that resembles the one shown below, with one div on top and two divs under it. I would prefer not to use tables, ensuring there is no space between the divs, and if possible, having collapsed borders. _________ | ...

What methods can I utilize to increase the speed of my JavaScript animation?

Recently, I implemented a Vue component designed to loop a div over the X axis. While it functions correctly, I can't help but notice that it is consuming an excessive amount of CPU. I am interested in optimizing this animation for better performance. ...

Tips on activating two HTML buttons simultaneously

I tried to implement clickable tabs by following a tutorial. I created both horizontal and vertical tabs. However, I want to have both buttons active at the same time. For example, if any of the horizontal buttons is active (number less than 6), then the f ...

Tips for ensuring Opera browser compatibility with buttons using the CSS background image property

Is there a way to make background images work on buttons in Opera web browser using CSS? I've tried using the background image property, but it doesn't show up when I use Opera. Strangely enough, it works fine in Firefox. However, I have noticed ...

What is the best way to place a parent div above its child element?

I'm currently dealing with a container div styled with background-color: red;. This container has around 12 children, and the last child is set with background-color: blue;. My goal was to position the container on top of the child with the blue backg ...