Adjusting the width of a button can result in gaps forming between neighboring buttons

I am currently working on a calculator project that involves customizing the width of a specific button with the ID equal. However, when I adjust the width of this button, it results in unexpected spacing between the third and fourth buttons in each row, consequently altering the overall table layout as well. Below is the excerpt of my HTML and CSS code:

table {

border: 1px solid rgb(180, 172, 172); 
background-color: aliceblue;
margin-left: auto; 
margin-right: auto; 
border-spacing: 6px;
border-radius: 1rem;
outline: none;
-webkit-box-shadow:0px 10px 39px 10px rgba(62,66,66,0.22);
-moz-box-shadow: 0px 10px 39px 10px rgba(62,66,66,0.22);
 box-shadow: 0px 10px 39px 10px rgba(62,66,66,0.22);
 } 
 #result {
margin-top: 5px;
height: 11vh;
width: 350px;
background-color: #E8E8E8;
border: 1px solid #E8E8E8;
border-radius: 5rem;  
 }
input[type="button"] { 
width: 60px;
height:9vh; 
background-color: #E8E8E8;; 
color: white; 
font-size: 24px; 
font-weight: bold; 
border: none; 
border-radius: 5rem; 
} 
#equal {
width: 140px!important;
}
<table id="calc"> 
    <tr>
        <td colspan="4"><input type="text" id="result"></td>
    </tr>
    <tr>
        <td><input type="button" id="AC"></td>
        <td><input type="button" id="C"></td>
        <td><input type="button" id="%"></td>
        <td><input type="button" id="/"></td>
    </tr>
    <tr>
        <td><input type="button" id="7"></td>
        <td><input type="button" id="8"></td>
        <td><input type="button" id="9"></td>
        <td><input type="button" id="x"></td>
    </tr>
    <tr>
        <td><input type="button" id="4"></td>
        <td><input type="button" id="5"></td>
        <td><input type="button" id="6"></td>
        <td><input type="button" id="-"></td>
    </tr>
    <tr>
        <td><input type="button" id="1"></td>
        <td><input type="button" id="2"></td>
        <td><input type="button" id="3"></td>
        <td><input type="button" id="+"></td>
    </tr>
    <tr>
        <td><input type="button" id="0"></td>
        <td><input type="button" id="."></td>
        <td><input type="button" id="equal"></td>
    </tr>
</table>

In an attempt to work around this issue, I decided to remove the width property and experiment with padding instead. Unfortunately, this led to unintended changes in the button widths at the top of the calculator.

Answer №1

Your table currently has 4 columns, but the last row only has 3 columns. Simply add a colspan=2 attribute to your last td tag.

Instead of:

<td><input type="button" id="equal"></td>

Use:

<td colspan=2><input type="button" id="equal"></td>

With this modification, your code should work correctly.

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

An instructional HTML/JS dialogue for a linked page

On my website, there is a link that, when clicked, opens a new tab with a page that I don't control. I want to guide the user on what to do next after they are redirected to this new page ("Now please press the green button on this page"). Ideally, I ...

Create a fresh array by merging two existing arrays while maintaining the order of values

I have a pair of arrays: array one: ( [0] => 2 [1] => 5 ) array two: ( [0] => Sentry [1] => Maxima ) and I'm attempting to create a new array that resembles the following new array: ( ["Sentry"] => 2 ["Maxima ...

Assigning a new classification to the primary object in the evolving array of objects

I'm working with an element that loops through all the objects using v-for and has a CSS class named top-class{}... I need to dynamically add the top-class to the first object (object[0]) and update it based on changes, removing the old top-class in t ...

What is the best way to implement an if-else structure in this code?

Can anyone help me with converting this code into an if/else statement? I want it to display certain content if 'Rental' is true, and other content if it's false. The PHP tags are making it difficult for me to follow. <?php if( get_ ...

Turn off the ability for items in Isotope to be set to an absolute

Currently, I am customizing my portfolio and looking to implement my own method for positioning the portfolio items. The Isotope library typically uses absolute positioning with left and top properties to position portfolio elements. Even after trying to o ...

Successfully resolved: Inability to dynamically adjust button color according to its state

Currently I am working on a feature where a button changes color when it is disabled, but also has a custom color when enabled. Here is the code snippet I am using: Despite setting blue text for the button, it remains blue even after becoming disabled. Ho ...

What could be causing my footer to be stuck in the center of my webpage?

Despite trying various methods, my footer remains stuck in the middle of the page. I even attempted to set the body height to 100% or 100vh without success. footer placement issue (https://i.stack.imgur.com/qzp2i.png) css: body { display: flex; flex-direct ...

An elementary React project facing compilation issues

I'm currently exploring react hooks, but I encountered an error with the useReducer hook. The console displays the following error message: "Invalid hook call. Hooks can only be called inside of the body of a function component. This could happe ...

Creating a handshake process for hybi-17

I am currently in the process of creating the handshake for the websocket hybi-17 protocol. I have been referencing the draft available at . Based on the guidelines provided in the draft, I have developed the following code snippets for both the client (us ...

Modifying the color of the tooltip arrow in Bootstrap 4: A step-by-step guide

How can I change the arrow color of the tooltip using Bootstrap 4? Here is my current code: HTML: <div class="tooltip-main" data-toggle="tooltip" data-placement="top" data-original-title="Service fee helps Driveoo run the platform and provide dedicate ...

Prevent scrolling within input field

I have a text entry field with background images that separate each letter into its own box. Unfortunately, an issue arises when I reach the end of the input: the view automatically scrolls down because the cursor is positioned after the last letter enter ...

Discovering content between HTML tags using Python Regular Expressions

Can someone help me with extracting the content between HTML tags shown here: <div class="td-wrap"> <a href="/universities/university-cambridge" class="uni-link">University of Cambridge </a> </div> ...

Choose a radio button with a dynamic value in Selenium

How can I automatically select the radio button below with a changing value attribute? HTML: <form name="ViewQueryForm" method="post" action="/equery/getAttachments.do"> <div class="txt_align_left innerdvcont&q ...

What is the process for aligning Item1 to the left and Item2 & Item3 to the right using MUI React?

I'm working on a component that contains three different Typography components. I need to align "summary" to the left, while 'miles' and 'duration' should be aligned to the right. https://i.stack.imgur.com/7e9sY.png Here's t ...

Displaying a Color Sample in a Grid

I'm currently working on a feature that allows users to select colors using the jQuery minicolor widget. I really like how the color swatch appears inside the widget, but I'm having trouble replicating that same look in a data table. When I try t ...

Apply a chosen style to the element that was clicked on, while removing the style from the rest

Here is an example of my ul li structure: <div id="categoryTree"> <ul> <li id="cat_15"> <a class="hasSubCat" href="javascript:void(0);"><img src="images/icons/folder.gif" border="0" alt="Folder" title=" Folder ">N ...

Animate a div once the parent section becomes visible while scrolling

I previously had this function working, but it seems that I have somehow messed it up in the process. My current setup includes a scroll hijack feature that navigates users to a new section or card each time they scroll. The script adds a visible class w ...

jQuery .click() only triggering upon page load

I've been searching all over the place and I just can't seem to find a solution to my specific situation. But here's what I'm dealing with: Instead of using inline HTML onclick, I'm trying to use jQuery click() like this $(docume ...

How to Manage Empty Lines in HTML Documents within WordPress

Just recently, I launched my brand new website. Everything seems to be functioning properly except for one issue that I discovered in the HTML source code. There are 15 blank lines before "<!doctype html>", which is causing some problems with SEO and ...

When using v-select to search for items, the selected items mysteriously vanish from

I recently worked on a project where I encountered a similar situation to the one showcased in this CodePen. Here is the link to the specific CodePen One issue I faced was that the selected items would disappear when performing an invalid search. After i ...