简体   繁体   中英

HTML/CSS: Extra spacing above and below text-type input

Live example: http://jsfiddle.net/yDQXG/

What I see in Chrome: http://i.imgur.com/shLfA.png

I can't seem to figure out where the spacing around the input element (blue fields) is coming from. Any ideas?

<form method="get">
<fieldset class="halfblock">
    <input class="blockheader" type="text" value="Field A">
    <textarea class="blocktext" rows="5">Line 1&#13;&#10;Line 2</textarea>
</fieldset>
</form>

It's because they are inline elements. Same thing happens often with images.

All you need to do is add display:block to your inputs:

input.blockheader {
    margin: 0;
    padding: 0;
    text-align: center;
    background: #ABD9E2;
    font: 11px/11px 'Vollkorn', serif;
    border: none;
    width: 100%;
    position: relative;
    /* top: -7px; */

    display: block;
}

set line-height: 0px; on .halfblock

.quote_body .halfblock {
    width: 262px;
    border: 1px dotted 
    #333;
    float: left;
    margin-bottom: 15px;
    line-height: 0px;
}

Add the display tag to the input's CSS:

input.blockheader {
    display: block;
}

Problem solved.

Set:

.halfblock & .thirdblock to:

line-height:0px

Also consider the option of adding a CSS reset

http://meyerweb.com/eric/tools/css/reset/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM