Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6604399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:09:03+00:00 2026-05-25T19:09:03+00:00

Here is the live demo I’m trying to put a padded text input inside

  • 0

Here is the live demo

I’m trying to put a padded text input inside a td, and I want it to occupy 100% of the width, but it goes outside of the td.
I don’t understand why that happens, anybody knows?

CSS

  table{
    border: solid 1px gray;
    width: 90%;
  }
  input{ width: 100%; padding:10px; }

HTML

<table>
  <tr>
    <td style="width:150px;">Hello</td>
    <td><input type='text' value='hihihih'/></td>
  </tr>
</table>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:09:04+00:00Added an answer on May 25, 2026 at 7:09 pm

    Explanation

    Here’s a link to the W3C Box model which explain in detail what happens to your element.

    W3C box model – – – – – the two box models

    All input elements have borders by default and may also have padding and margins, but most importantly, it follows the W3C box model specifications using the content-box.

    This means that if you set the width to 100%, the actual size of the element will be greater than 100% when you include padding/borders, as shown in the images above.


    Solution

    Add padding to the td to manually adjust the width of the input until it’s where you want it to be. Remember that adding padding to the input means you have to add the same amount to the td to counteract the expansion.

    Here’s a live example

    input {
        width: 100%;
        padding: 10px;
        margin: 0px;
    }
    
    table .last, td:last-child { 
        padding: 2px 24px 2px 0px; 
    }
    

    Alternative solution

    You can also do the CSS3 version using box sizing (browser compatability).
    This property can be used to switch between the two box models and will make it behave like you’d expect it to.

    Here’s a live example

    input {
        width: 100%;
        padding: 10px;
        margin: 0px;
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
    }
    

    Here are some possible duplicates of the same question

    • can i stop 100% width text boxes from extending beyond their containers
    • Problem with input type=’text’ and textarea width
    • 100% Width div’s and form elements + padding?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a little example: (live demo here ) HTML: <input id=file type=file />
Live demo: http://jsfiddle.net/9Y7Cm/1/ I want the text to be placed at the 50% of
This is live demo: http://jsfiddle.net/9Y7Cm/5/ Everything is fine with that, until the text width
Consider the following example: ( live demo here ) HTML: <label>Name</label> CSS: label {
Consider the following example: ( live demo here ) HTML: <div id=outer_wrapper> <div class=wrapper>
Here's a live demo for your convenience: http://jsfiddle.net/Lr6NQ/2/ On ul#navigation ul , if there
Here's a live demo . I have the following html: <div class=Q> <div id=Q3><span>1.
Consider the following example which should color every second row: ( live demo here
Here's a live demo of the issue on JS Fiddle. I have some jquery
Consider the following code: ( Live demo here - Open in Internet Explorer 7

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.