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

  • Home
  • SEARCH
  • 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 7087869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:43:38+00:00 2026-05-28T07:43:38+00:00

I am trying to do some quite precise styling on some form elements, and

  • 0

I am trying to do some quite precise styling on some form elements, and this issue is causing me a lot of grief.

If I try to remove padding, margin, border and outline from an <input> (with display: block) so that the size of the field is purely determined by the text, the input field ends up having a few pixels extra padding than any other block level element styled exactly the same way. Here’s an example:
http://jsfiddle.net/nottrobin/b9zfa/

<input class="normalised testSubject" value="hello" />
<div class="normalised testSubject">hello</div>

Rendering:

Rendering

In that example, the <div> gets a computed height of 16px while the <input> gets a computed height of 19px.

I get the same behaviour in Chrome 16, Firefox 9 and Opera 11 so it’s clearly rendering engine independent.

I can fix the issue by manually adding a height, but I don’t want to do that because I want the design to remain responsive.

Can anyone help me understand what’s going on here, and how I can reliably make sure that the <input> will be the same height as any block level element that follows it?

  • 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-28T07:43:39+00:00Added an answer on May 28, 2026 at 7:43 am

    The <input> has a minimum line-height based on font size. Setting both elements to a larger line-height value works, as does removing line-height altogether. But that still doesn’t allow you to have smaller heights than the minimum. The fix for that is using the first-line pseudo-element and setting it to display: inline-block;.

    Demo: http://jsfiddle.net/ThinkingStiff/B7cmQ/

    enter image description here

    CSS:

    .normalised:first-line {
        display: inline-block;    
    }
    

    But this doesn’t explain why the <input> is acting differently than the <div>. Even -webkit-appearance: none; didn’t fix it. It would seem there is some invisible voodoo on inputs that treats its contents as inline. inline elements have minimun line-height based on font size, which is the behavior we’re seeing here. That’s why first-line fixes it. It seems to be styling the “child” element of the <input>.

    Here’s a demo that shows the minimum line-height on inline elements. The <div> element honors line-height: 7px;. The <span>, even though its computed value is showing 7px;, is not honoring it visually.

    Demo: http://jsfiddle.net/ThinkingStiff/zhReb/

    Output:

    enter image description here

    HTML:

    <div id="container"> 
        <div id="div-large">div <br />large</div> 
    </div> 
    <div id="container"> 
        <div id="div-medium">div <br />med</div> 
    </div> 
    <div id="container"> 
        <div id="div-small">div <br />small</div> 
    </div> 
    <div id="container"> 
        <span id="span-large">span <br />large</span> 
    </div> 
    <div id="container"> 
        <span id="span-medium">span <br />med</span> 
    </div> 
    <div id="container"> 
        <span id="span-small">span <br />small</span> 
    </div> 
    

    CSS:

    #container { 
        background-color: lightblue;   
        display: inline-block; 
        height: 200px; 
        vertical-align: top; 
    }
    
    #div-large { 
        line-height: 50px; 
    } 
    
    #div-medium { 
        line-height: 20px; 
    } 
    
    #div-small { 
        line-height: 7px; 
    }
    
    #span-large { 
        line-height: 50px; 
        vertical-align: top; 
    } 
    
    #span-medium {
        line-height: 20px; 
        vertical-align: top; 
    } 
    
    #span-small {
        line-height: 7px;
        vertical-align: top;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

been trying out this for quite some time but I'm still unable to built
This has been bothering me for quite some time. I'm simply trying to change
I have sat for quite some time trying to work this out and just
I was trying to figure this out for quite some time.I want a Databind
I've been dealing with this problem for quite some time. What I am trying
I spend quite some hours banging my head against the wall trying to set
I'm trying to make it working for quite some time,but just can't seem to
Recently I was trying some practice programs in python and I came across this
I've been doing .NET and C# programming for quite some time, but this is
So, I have built on this system for quite some time, and it is

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.