How come the vertical positioning of my HTML button in a <td> is affected when I include an image?

https://i.sstatic.net/AetS4.pngI typically include only text on my buttons, which maintains the vertical alignment of the buttons within the <td> element (Code-1).

However, when I add an image to the button, the alignment is thrown off. The height of the <td> increases and the button aligns to the bottom. What could be causing this issue?

.td_button_bar {
  background-color: #eaf2f8;
  border: none;
  left: 10px;
}

.button {
  width: 75px;
  height: 50px;
  background-color: #eaf2f8;
  border: 1px solid;
  border-color: #aed6f1;
  display: inline-block;
  font-size: 13px;
  border-radius: 5px 5px 5px 5px;
  color: #212f3c;
  padding-top: 10px;
}
Code-1 vert.alignment OK:
<table>
  <tr class="tr_button_bar">
    <td class="td_button_bar" align="left" valign="middle">
      &nbsp;<button class="button">Connect</button> &nbsp;
      <button class="button">Disconnect</button>
    </td>
  </tr>
</table>
Code-2 vert.alignment Not OK:
<table>
  <tr class="tr_button_bar">
    <td class="td_button_bar" align="left" valign="middle">
      &nbsp;<button class="button"><img src="https://w7.pngwing.com/pngs/923/71/png-transparent-computer-icons-connect-miscellaneous-angle-technology-thumbnail.png" width="20" height="20" align="middle">Connect</button> &nbsp;
      <button class="button"><img src="https://w7.pngwing.com/pngs/627/934/png-transparent-computer-icons-electrical-connector-ac-power-plugs-and-sockets-plug-in-connect-miscellaneous-computer-program-electrical-connector-thumbnail.png" width="20" height="20" align="middle">Disconnect</button>
    </td>
  </tr>
</table>

Answer №1

For optimal image and text alignment within a button, consider adding the following CSS properties: margin-top: 0; and padding: 0 0 0 0;.

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

Transferring User Information from PHP/HTML to AngularJS

As a beginner in AngularJS, I am still navigating my way through its functionalities. One question that I couldn't find an answer to on this platform relates to building a conventional HTML/PHP list website where data, such as a list ID, is passed fro ...

Angular - Load HTML content dynamically with included Angular syntax

When working with Angular 9+, I have found a way to convert a string into HTML and then load that HTML using innerHTML along with bypassSecurityTrustHtml(). My concern is whether it is feasible to dynamically render the converted HTML to properly include ...

PHP displays an HTML table with error messages

I recently created a table by extracting data from a database using a loop to retrieve all the necessary information. However, I encountered an error after calling a javascript function in the HTML onClick event of an input element. The function itself wor ...

Applying CSS to inherit styles

I have a group of divs with a similar style, but each one has different padding and margin settings. Here is an example: <div class="mainStyle" id="cc">CC</div> <div class="mainStyle" id="bb">BB</div> <div class="mainStyle" id=" ...

Leverage htaccess functionality to modify website configurations without altering the URL

I currently have the following htaccess configuration: <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ dl.php?id=/$1 [QSA,L] </IfModule> It works perfectly fine. However, I am facing a problem with my site URLs and images ...

Need to know how to retrieve the li element in a ul that does not have an index of 2? I am aware of how to obtain the index greater than or less

I'm looking to hide all the li elements except for the one with a specific index. I've written some code to achieve this, but I'm wondering if there's a simpler way using jQuery. While jQuery provides methods like eq, gt, and lt, there ...

Attempting to make Navbar vanish as the page size decreases

I am a beginner in html and css and my instructor wants us to create a resume using bootstrap. Bootstrap is designed to provide interactive design that adjusts seamlessly across different devices. I am currently working on aligning elements and I would lik ...

Design a CSS floating div with a captivating bubble effect

My current setup includes a DIV element styled as follows: <div class="modal"></div> .modal { position: fixed; z-index: 999999; right: 310px; top: 67px; width: 431.6px; height: 550px; border-radius: 25px; box-s ...

There seems to be an issue with Bootstrap: the property this._config is

Here is the button I have: <button class="kv_styleclass_0 btn btn-outline-success btn-lg" data-bs-toggle="modal" data-bs-target="formModal" type="button"> Become a participant </button ...

What is the best way to position a div at the bottom of the main div?

How can I position a div with the class "boxLinks" at the bottom of the main box with the class "main-box"? Here's my idea: The main class has a width of 1200px; within this main class, there are 5 divs with each div having a width of 25%. .main- ...

What is the process for transferring inputted values from a form on one HTML page to variables on another HTML page?

For the website I am currently developing, I have implemented a form on an options page with the following code: <form method="POST" action="process.asp" name="form1"> <table width="70%" border="0" cellspacing="0" cellpadding="0"> ...

Incorporating Bootstrap with Leaflet: A Seamless Integration

Having trouble integrating my bootstrap-based website with a Leaflet webmap. There seems to be a vertical shift in the Mapbox tiles. I suspect it's a conflict between the .css files of Bootstrap and Leaflet. You can check out my webpage at this link ...

Is it possible to have a PHP variable embedded within an HTML link tag?

<?php $message = ' <a href="' . $link . '">here</a> '; ?> My goal is to include a clickable link in the $message variable for use in the mail() function. However, despite setting $link with the desired link string, it ...

Passing the value of each table row using Ajax

On my webpage, I have a list of orders displayed. I'm facing an issue where the value of each row in the table is not being passed correctly to my controller and database when a user clicks on a button - it always shows null. Can someone please assist ...

Adding JSON data to an HTML page in a list format

Currently, I am working on extracting data from MySQL and displaying it on an HTML page. This is the code I have written so far in my tenantlistmob.php: <?php include('connection.php'); $result = mysql_query("SELECT * FROM tenanttemp" ...

Embed the YouTube video using the URL in the video tag

I tried using the <video> tag, but I'm having trouble getting it to play videos from YouTube. Even though I found this http://jsfiddle.net/wCrNw/, it doesn't seem to work as expected. I also consulted Show Youtube video source into HTML5 ...

What is the best way to align icons in the center alongside text or paragraphs using react?

I'm struggling with centering my icons like <GrTools size="30px"/> next to my text. It's causing some alignment issues with my styled components. Here is my JavaScript: <div id='paragraph' className="container"> ...

Leveraging jQuery to target the div element labeled with class "signed" through a Ruby

I'm attempting to create a click event that allows a user to click a link to toggle a dropdown window, with only one window open at a time. $(".one").on('click', function(){ $(".two").slideToggle(); }); <div class="row visual_wra ...

What could be causing AngularJS to truncate my URL in the search bar?

Currently, I am in the process of setting up a state provider for a CRUD website. One issue I encountered is that when I navigate to www.mysite.com/posts/mypost, the URL gets shortened to www.mysite.com/mypost and does not trigger the controller as intend ...

How can I vertically align a photo or image on Facebook?

Can anyone explain how Facebook manages to vertically align its photos without using padding or margins? I've looked into their img tag and its parent, but neither seem to have any spacing properties. Although there is a vertical-align attribute prese ...