Text overflow issue within an HTML table

Currently, I am working on developing a calculator using Javascript but I have encountered an issue with the design. The text box display is extending beyond the border of the table cell. Below is the

 /*The Style file is as follows*/
 
 table{
    border:1px solid silver;
    border-radius:5px;
    }
    
    .btn{
    width:75px;
    height:45px;
    }
    
    #equalToBtn{
    background-color:blue;
    color:white;
    border-color:blue;
    }
    
    #resultText{
    width:100%;
    height:40px;
    margin-right:2px;
    }
<!--HTML code-->

    <!DOCTYPE html>
    <html>
    <head>
    <link rel="stylesheet" href="calculator.css">
    </head>
    <body>
    <table>
    <tr>
    <td colspan="4"><input type="text" id="resultText"></td>
    </tr>
    <tr>
    <td><button class="btn" type="button">7</button></td>
    <td><button class="btn" type="button">8</button></td>
    <td><button class="btn" type="button">9</button></td>
    <td><button class="btn" type="button">/</button></td>
    </tr>
    <tr>
    <td><button class="btn" type="button">4</button></td>
    <td><button class="btn" type="button">5</button></td>
    <td><button class="btn" type="button">6</button></td>
    <td><button class="btn" type="button">*</button></td>
    </tr>
    <tr>
    <td><button class="btn" type="button">1</button></td>
    <td><button class="btn" type="button">2</button></td>
    <td><button class="btn" type="button">3</button></td>
    <td><button class="btn" type="button">-</button></td>
    </tr>
    <tr>
    <td><button class="btn" type="button">0</button></td>
    <td><button class="btn" type="button">.</button></td>
    <td><button class="btn" id="equalToBtn" type="button">=</button></td>
    <td><button class="btn" type="button">+</button></td>
    </tr>
    </table>
    </body>
    </html>



   

I have set the width of the text to 100% but it's causing overflow. I would greatly appreciate any assistance.

Thanks in advance!!!

Answer №1

inserted

*{
box-sizing: border-box;
}

The issue resolved was caused by the padding applied to the input element. I trust this explanation assists you in understanding.

/*Below is the content of the CSS style file*/

*{
box-sizing: border-box;
}

 table{
    border:1px solid silver;
    border-radius:5px;
    }
    
    .btn{
    width:75px;
    height:45px;
    }
    
    #equalToBtn{
    background-color:blue;
    color:white;
    border-color:blue;
    }
    
    #resultText{
    width:100%;
    height:40px;
    margin-right:2px;
    }
<!--HTML code-->

    <!DOCTYPE html>
    <html>
    <head>
    <link rel="stylesheet" href="calculator.css">
    </head>
    <body>
    <table>
    <tr>
    <td colspan="4"><input type="text" id="resultText"></td>
    </tr>
    <tr>
    <td><button class="btn" type="button">7</button></td>
    <td><button class="btn" type="button">8</button></td>
    <td><button class="btn" type="button">9</button></td>
    <td><button class="btn" type="button">/</button></td>
    </tr>
    <tr>
    <td><button class="btn" type="button">4</button></td>
    <td><button class="btn" type="button">5</button></td>
    <td><button class="btn" type="button">6</button></td>
    <td><button class="btn" type="button">*</button></td>
    </tr>
    <tr>
    <td><button class="btn" type="button">1</button></td>
    <td><button class="btn" type="button">2</button></td>
    <td><button class="btn" type="button">3</button></td>
    <td><button class="btn" type="button">-</button></td>
    </tr>
    <tr>
    <td><button class="btn" type="button">0</button></td>
    <td><button class="btn" type="button">.</button></td>
    <td><button class="btn" id="equalToBtn" type="button">=</button></td>
    <td><button class="btn" type="button">+</button></td>
    </tr>
    </table>
    </body>
    </html>

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

Creating a dynamic slideshow with automated arrow navigation is simpler than you may think

I have successfully tested the slideshow and it is functioning perfectly without any issues. I would like to have a dual slideshow setup (slideshow 1 and slideshow 2) with next and previous buttons, but I am interested in adding an automatic sliding featur ...

Minimize the length of text extracted in an HTML template with Django

I am seeking a way to shorten text content that is retrieved in an HTML template to display as a preview, rather than displaying the full block of text. Original Text: aaaaaaaaaaaaaaaaaaaaaaaaaaa.... The code snippet used to retrieve the contents is: ...

The script functions perfectly on one page, but encounters issues on another page

I'm currently working on developing an iOS7 WebApp using a template that I came across on this website: After writing some JavaScript/jQuery to create a fading effect for a picture and a toolbar, and testing it successfully on a blank page, I encount ...

Learn the art of incorporating items and attributes into HTML through JavaScript or jQuery by extracting information from a csv or json file

As someone who is not a web developer, I am seeking to enhance the maintainability of the code below. My idea is to simplify the process using an appropriate method. I aim to dynamically inject content and attributes into an HTML file by utilizing either ...

Strange behavior occurs when CSS content elements utilize :before pseudo element with images

I'm having trouble placing three different images in front of some list points on my website. It doesn't seem to be working the way I intended. Can anyone offer some assistance? Currently, it appears like this: CSS content Despite using :before ...

What is the process of creating a file containing variables for all of the colors used in a project?

When I develop a website using React.JS, my goal is to consolidate all color definitions within a single class. Admittedly, I am quite new to this and currently only work with colors through CSS files, such as the following example: .toolbar { backgr ...

Exploring the CSS Cube Effect within a React Environment

I am currently attempting to replicate a cube within a webpage I am constructing using react (I am relatively new to react, so please bear with me if this is a novice question) Link to Cube Visualization Creating a component that contains the HTML struct ...

Center text with font awesome symbols

I'm looking for a way to vertically align text next to my FontAwesome icons without using manual padding. Is there a better method for achieving this? https://i.stack.imgur.com/PWwSJ.jpg <div class="row"> <div id="tb-testimonial" class="tes ...

Implementation of jQuery Pin It Feature

I'm attempting to create a sticky navigation bar for my website, contemporarypool.biz, using jquery.pin. However, I am fairly new to the realm of javascript and have been struggling to successfully implement this script. Although I have included the j ...

Elementor custom CSS for Wordpress header

I've been struggling to make my header transparent and then change to a colored background when scrolling down. I tried following the instructions in a video, but I couldn't find the OFFSET EFFECT setting. WEBSITE: Video: https://www.youtube.co ...

Show Section, Delay Function, Conceal Section

How can I make an image appear when a div is clicked on and then disappear after 3 seconds? The function I have only makes the image appear, but adding a timeout does not work. Any suggestions on how to fix this issue? (Additionally, if someone could prov ...

Customize your Bootstrap 4 card: change the header content, keep the body fixed

My current project involves the use of a bootstrap 4 card element: <div class="card" style="height:"500px;width:100px"> <div class="card-body"> <div class="top-portion"> This section can b ...

What is the process to modify the font color on a webpage using a button?

I need some help figuring out how to change the font color on my website when someone clicks a button. I already have the background functionality working, but I can't seem to get the text color to change. This is the code I have so far: <div cl ...

Guide for splitting an HTML webpage into 3 separate divs with individual scrolling feature

Currently, I'm working on creating a website with three columns that allows users to scroll down each one independently. I attempted to set the columns at 33% width, but whenever I add content, a strange gap appears at the bottom of the screen and pr ...

Using RMarkdown to incorporate custom CSS styling in your documents

Having some trouble with my HTML report created from RMarkdown and applying CSS. The browser version displays correctly, but when printed, the styling doesn't come through. Below is an example of the RMarkdown code: --- title: "Table" output: html_ ...

Is HTML5 readTransaction available on iPad (iOS 3.2)?

My HTML5 application relies on websql for data storage. For read-only SELECT queries, I utilize the readTransaction() method as much as possible, while for INSERT/UPDATE/DELETE queries, I use the transaction() method. Although I'm unsure if using re ...

loading html title dynamically

Below is a snippet from my HTML code: <img src="<?php echo get_post_meta($post->ID, 'thumbnail_value', true); ?>" title="<?php the_tags(); ?>" alt="" class="thumb"></a> In the "title" attribute, I have included &l ...

When clicked, the onClick feature will reduce the number each time instead of initiating the timer

Currently, I am working on a meditation application using React. As a starting point, I implemented a 25-minute countdown feature. The challenge I am facing is that the timer starts counting down each time the button is clicked, rather than triggering it ...

Tips for redirecting a HTML page to two different pages by utilizing two separate buttons:

To link to another HTML page, you can use the code below triggered by a button click: <form action="where-you-want-to-go"><input type="submit"></form> However, I am encountering an issue. How can I direct two different buttons on the sa ...

Safari does not support the creation or addition of elements using JavaScript

Having a bit of an issue with my JavaScript function here. It's supposed to add two Options to a select drop down list when a button is clicked, but for some reason, it's only working in Firefox and Chrome - Safari seems to be giving me trouble. ...