Ways to expand HTML input fields to fill the whole table cell

Currently working on a calculator project and I'm facing an issue with making a HTML button span the entire cell. I've managed to stretch the button horizontally but struggling to get it to fill the cell completely. Curious as to why setting width:100% works in my .buttons class but adding height:100% doesn't have any effect at all?

body {
  background-image: url("images/background.jpg");
  background-color: #cccccc;
}

.square {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: 900px;
  width: 1200px;
  background-color: rgb(255, 255, 255);
  outline: 5px solid rgb(0, 0, 0);
}

.calculator {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: 700px;
  width: 500px;
  background-color: rgb(255, 255, 255);
  outline: 5px solid rgb(0, 0, 0);
  border-radius: 5px;
}

input {
  width: 100%;
  height: 100%
}

table {
  width: 501px;
  height: 700px;
}
<body>
  <div class="square">
    <div class="calculator">
      <form method="post">
        <table border="1" width=100%>
          <tr>
            <td colspan="4">
              <input type="text" id="inputbox" />
            </td>
          </tr>
          <tr>
            <td colspan="3"><input type="submit" name="reset" value="RESET" /></td>
            <td><input type="submit" name="divide" value="/" /></td>
          </tr>
          <tr>
            <td><input type="submit" name="7" value="7" /></td>
            <td><input type="submit" name="8" value="8" /></td>
            <td><input type="submit" name="9" value="9" /></td>
            <td><input type="submit" name="multiply" value="*" /></td>
          </tr>
          <tr>
            <td><input type="submit" name="4" value="4" /></td>
            <td><input type="submit" name="5" value="5" /></td>
            <td><input type="submit" name="6" value="6" /></td>
            <td><input type="submit" name="minus" value="-" /></td>
          </tr>
          <tr>
            <td><input type="submit" name="1" class="buttons" value="1" /></td>
            <td><input type="submit" name="2" value="2" /></td>
            <td><input type="submit" name="3" value="3" /></td>
            <td><input type="submit" name="add" value="+" /></td>
          </tr>
          <tr>
            <td colspan="2"><input type="submit" name="0" value="0" /></td>
            <td><input type="submit" name="point" value="." /></td>
            <td><input type="submit" name="result" value="=" /></td>
          </tr>
        </table>
      </form>
    </div>
  </div>
</body>

Answer №1

To ensure input buttons fill the entire width and height, use width: 100%; and height: 100%. For Safari and Firefox compatibility, include -webkit-appearance: none;

body {
  background-image: url("images/background.jpg");
  background-color: #cccccc;
}
.square {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: 900px;
  width: 1200px;
  background-color: rgb(255, 255, 255);
  outline: 5px solid rgb(0, 0, 0);
}
.calculator {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: 700px;
  width: 500px;
  background-color: rgb(255, 255, 255);
  outline: 5px solid rgb(0, 0, 0);
  border-radius: 5px;
}

table {
  width: 501px;
  height: 700px;
}
.buttons {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  text-align: center;
}
#inputbox{
background: #6b6b6b;
color:black;
}
input{
width:100%;
height:100%;
font-size: 22px;
outline: none;
border:0;
background: #3f3f3f;
cursor: pointer;
color: white;
-webkit-appearance: none; 
}
<link rel="stylesheet" href="styles.css">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<div class="square">
  <div class="calculator">
    <table border="1" width=100%>
      <tr>
        <td colspan="4">
          <input type="text" id="inputbox" />
        </td>
      </tr>
      <tr>
        <td colspan="3"><input type="submit" name="display" value="RESET" /></td>
        <td><input type="submit" value="/" /></td>
      </tr>
      <tr>
        <td><input type="submit" value="7" /></td>
        <td><input type="submit" value="8" /></td>
        <td><input type="submit" value="9" /></td>
        <td><input type="submit" value="*" /></td>
      </tr>
      <tr>
        <td><input type="submit" value="4" /></td>
        <td><input type="submit" value="5" /></td>
        <td><input type="submit" value="6" /></td>
        <td><input type="submit" value="-" /></td>
      </tr>
      <tr>
        <td><input type="submit" value="1" /></td>
        <td><input type="submit" value="2" /></td>
        <td><input type="submit" value="3" /></td>
        <td><input type="submit" value="+" /></td>
      </tr>
      <tr>
        <td colspan="2"><input type="submit" value="0" /></td>
        <td><input type="submit" value="." /></td>
        <td><input type="submit" value="=" /></td>
      </tr>
    </table>
  </div>
</div>

View the snippet on CodePen

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

Is it possible to have evenly spaced divisions within a fixed wrapper?

I have been experimenting with creating a dynamic navbar that remains at the top of a webpage. Here's what I have so far: <style> .sticky-nav-wrapper > div { color: #000000; display: inline-block; display: -moz-inline-box; * ...

Using Javascript to extract and organize JSON arrays from various sets of checkboxes

Is there a way to automatically create an array of multiple groups of arrays like this: arr = {arr1:{index:value, index2:value2}, arr2:{index,value, index2:value2}}; The order is based on groups of checkboxes in HTML (see example below): <div class=& ...

Is there a way to refresh only a specific div when clicked?

My preferred tech stack includes Django and Python. Here is the scenario: In models.py : class Contacts(models.Model): lastname = models.CharField(max_length=150) firstname = models.CharField(max_length=150) In views.py def home(request): ...

The screen reader seems to be malfunctioning as soon as I include this particular code

//Finding the height of the header let headerHeight = document.querySelector('header'); let height = headerHeight.offsetHeight; //Adjusting the #navbarNav's top margin to accommodate the header let nn = docu ...

MUI provides the flexibility to adjust the opacity separately for Chip labels/icons and backgrounds

My objective is to customize the opacity of label/icon and background in MUI Chip. I want the label & icon to have an opacity of 1, while the background should have an opacity of 0.0571. Technologies used in this project include React, TypeScript, Materia ...

A new version of Primefaces has been released, introducing a sleek button feature with

How can I utilize the Primefaces version 10 button with a Font Awesome icon, resizing the icon without displaying the words ui:button? A and B are tests that I can resize successfully, but they are not buttons. C and D are buttons where the icon is resize ...

Troubleshooting CSS keyframe animation issues in IE and Edge

I have created an animation that works perfectly in all browsers except for IE and Edge. You can view the page here. .progress-container { position: relative; } .background-progress-bar, .progress-bar { width: 100%; height: 10px; top: 0px; left ...

Event listener is failing to execute the functions

Even though the inline onmouseover="verdadero()" function is properly set up Upon further inspection, it appears that while the event listener is added to the box element, the function is not being triggered when hovering over it, and console.lo ...

How can I stop jQuery mobile from updating the document title?

It appears that jQuery mobile automatically uses the text content of data-role="header" to set the document.title. For example: <div data-position="fixed" data-role="header"> <h1>This text</h1> </div> To work around this, I ha ...

Tips for creating a responsive floating page div

Hey there, I'm still fairly new to web development and have a question regarding a registration page that is displayed as a floating div above the main page. How can I ensure that this div is centered in a responsive way? The pages are separated and ...

Verify if any choices are available before displaying the div block

I need to determine if there is a specific option selected in a dropdown menu, and then display a div if the option exists, otherwise hide it. I'm not just checking the currently selected option, but all available options. if (jQuery(".sd select opti ...

Is there a way to reset back to the default CSS styles?

I have a div container with a nested span element (simplified). <div class="divDash"> <span>XX</span> </div> The CSS styling for the div makes the span initially hidden and only visible when hovering over the parent div. .div ...

Ways to customize the default font in themes by using locally stored fonts

Currently, I am utilizing Quarto for the creation of a website and attempting to modify the default fonts within a specific theme. My ultimate objective is to incorporate local Google fonts rather than relying on the Google API. In my _quarto.yml file, it ...

Embedding HTML within a PHP conditional statement

I recently encountered an issue while trying to display a source image using PHP. The initial code worked perfectly: <html> <h3>First Test</h3> <img src="example1.php" /> </html> However, I wanted to implement user validatio ...

Tips for accessing basic information from these websites without encountering CORS issues

Having issues retrieving data from the following two sites: and Eurolottery. The CORS issue is causing the problem, and I was able to retrieve data using a Chrome CORS extension and the provided code below: var HttpClient = function() { this.get = fu ...

Margin not being applied to last element in parent - any ideas why?

Why does the margin of the last element, whether it is a <p> or <h1>, not have any impact? It should be pushing the background of the parent container downwards. .container { background: grey; } h1 { margin-bottom: 3em } p { margin- ...

The <map> <area> element functions properly only in webkit browsers

Here is some HTML code: <div id="wrap"> <div id="main-content"> <div class="container"> <h1 class="logo">Mysite</h1> <img id="links" src="images/links.png" usemap="map" width="946" heigh ...

Styling a list using multiple columns with CSS

My goal is to design a columned list using only HTML and CSS. I have experimented with floats and inline-block, but it seems like inline-block is the best option for me due to these specific requirements: The layout must be in columns; The number of colu ...

Combining Node and React: Using CSS Class Names with Hyphens

Currently, my project utilizes react-starter-kit and includes several react components, each with its own styling file (scss). Every component imports the styling file at the top like this: import s from './Header.scss'; When it comes to using ...