SteveX
SteveX

Reputation: 67

How do I remove white space INSIDE CSS border? I want the border to be tight around the text

Here is my very basic test code:

<html>

    <head>
        <title></title>
    </head>
    <body style="font-size:100%; margin:0; padding:0;">

    <p style="border:1px solid red; font-size:10em; margin:0;">
    test</p>

    </body>
</html>

The problem is that as I increase the font size, the more white space is put above and below the text.

Is there a way to get the border to wrap tight around the text?

Thanks.

Upvotes: 2

Views: 9955

Answers (3)

Blender
Blender

Reputation: 298106

Using a CSS reset stylesheet makes things a lot easier for other browsers to handle, as many browser have their own defaults.

Just paste this huge line of CSS into your script, and it should look a bit more uniform (source: http://developer.yahoo.com/yui/3/cssreset/):

html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:text-top;}sub{vertical-align:text-bottom;}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;}input,textarea,select{*font-size:100%;}legend{color:#000;}

Now, @David Thomas's answer might look uniform.

Upvotes: 1

lazycs
lazycs

Reputation: 1604

Try playing with line-height:

<html>

    <head>
        <title></title>
    </head>
    <body style="font-size:100%; margin:0; padding:0;">

    <p style="border:1px solid red; font-size:10em; margin:0; line-height:0.5em">
    test</p>

    </body>
</html>

Upvotes: 1

David Thomas
David Thomas

Reputation: 253308

You should be able to use:

p {
    padding: 0; /* reduces the space between the content, and the border, of the p element */
    line-height: 1.2em; /* to avoid the text being 'squashed' together */
    font-size: 1em;
    border: 1px solid #000;
}

JS Fiddle

Upvotes: 2

Related Questions