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 8811001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:15:19+00:00 2026-06-14T03:15:19+00:00

How to use inputs with 100% width and margin/padding?? When the input has no

  • 0

How to use inputs with 100% width and margin/padding??

When the input has no focus the width is 2 pixel wider than the parent element, but on focus the width is right? How to solve this?! :-/

jsfidle

http://jsfiddle.net/eHQSR/1/

code

input, textarea {
    width:100%;
    -moz-box-sizing:border-box;
    -ms-box-sizing:border-box;
    -webkit-box-sizing:border-box;
    box-sizing:border-box;
}

input, textarea, button {
    display:inline-block;
    font-family:arial;
    margin:1px;
}

input, textarea {
    background-color:#FFFFFF;
    border:1px solid #297296;

    color:#333333;
    font-size:12px;
    padding:4px 4px;
}

input:focus, textarea:focus {
    border-color:#1a4c91;
    box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.07), 0 0 6px #7ab5d3;
    border-width:2px;
    margin:0px;
}

<div style="margin-top:20px; margin-left:20px">
    <div style="width:100px; background:red; float:left; margin:1px">
        <input type="text">
    </div>
    <div style="width:100px; background:red; float:left; margin:1px">
        <input type="text">
    </div>
</div>
  • 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-06-14T03:15:20+00:00Added an answer on June 14, 2026 at 3:15 am

    It’s because of your margin on the inputs, spacing them from the parent element (it’s worse when not using border-box but still occurs because margin is not included in the width calculation).

    input, textarea, button {
        display:inline-block;
        font-family:arial;
        margin:1px;
    }
    

    Instead, you can remove this inner margin and put 1px of padding on the parent: http://jsfiddle.net/eHQSR/3/

    Update

    As I said in the comment below, the extra border from the :focus styles was eating into your margin first which is why the height went unchanged. So I left the margin on there, removed the margin from the left, and then added the padding on just the left and right of the parent. So the width should be correct now and the height won’t "change" since it still eats into the margin above and below first (but as I noted, if you make the border any bigger it would still change the height of the input). All of this would be much simpler with a specified height somewhere.

    http://jsfiddle.net/eHQSR/5/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got following html structure: <div style=width:100%> <div style=float:left; width:70%><input /></div> <div style=float:left>element with
I have several inputs, they are created dynamically <input style=width:100% class=fileDescription type=text name=' +
The documentation says to use: $(input[type='checkbox']).bind( change, function(event, ui) { But I want to
Does anyone know why the input elements with a width of 100% go over
I'm trying to get a table to be 100% width of a div... But
I have 2 python scripts https://gist.github.com/2233477 . rsgen.py generates random inputs for use in
I can't use EditorFor because my inputs have some other attributes like readonly ,
i have two text inputs like the following, i don't want to use <form>
I'm working on a project and trying to use JavaScript for validating all inputs
Here is a code I use : request.jsf <h:form> <!-- form inputs ... -->

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.