By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,759 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,759 IT Pros & Developers. It's quick & easy.

Problem with line spacing when using display:inline

P: n/a
I have a small <div> element which contains two text blocks - one within
<h5> tags and the other within <p> tags.
I don't want any extra line spacing between elements so use the
display:inline property.

This works for IE6 but Opera7.54 and Netscape7.1 add large line spacing
between the text blocks and any lines of wrapped text.
The line spacing is independant of the font size and is consistent between
all lines.
ie: it's not larger between the <h5> and <p> lines than it is between the
wrapped <p> lines.

Because I'm trying to stick to W3C standards I used the doctype property.
As soon as the doctype is removed then the large line spacing disappears.
I ran the HTML code through the W3C validator and it validated without
errors.

Is it a rendering bug which IE6 doesn't suffer from (!!!) or am I missing
something?

Code sample is listed below.
The web page from which is was extracted will work fine without any doctype
declaration but I'd rather fix the problem properly.

*************************

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Test Page</title>
<style type="text/css">
<!--
..infoBody{font-size:10px; display:inline}
..infoHead{font-size:12px; display:inline}
..infoFrame{position:absolute; top:50px; left:50px; width:90px; height:100px;
background:cyan; text-align:center}
// -->
</style>
</head>

<body>

<div class="infoFrame">
<h5 class="infoHead">The Heading</h5>
<p class="infoBody"><br>This is some text which is spaced too large.</p>
</div>

</body>
</html>

Jul 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Danny@Kendal wrote:
I have a small <div> element which contains two text blocks - one within
<h5> tags and the other within <p> tags.
I don't want any extra line spacing between elements so use the
display:inline property.


Your problem is not block or inline positioning, but browser-default
margin and padding. Add:

margin: 0; padding: 0;

to each element styling and see them come together. Adjust as required -
try putting coloured borders around each element to see the effect.
margin and padding *must* have a unit of measure if non-zero.

Is <h5> really appropriate - do you have <h1>-<h4> defined, or are you
just using <h5> for font sizing? If the latter, don't. Use an
appropriate level and size the fonts to your desire.

Also, don't specify font sizes in px. 10px and 12px are smaller than
most people want to read, and cannot be resized in IE. Specify font
sizes as a percentage, with your main content no smaller than 100% (that
is, what *I* choose to set as my browser default).
--
Mark.
http://tranchant.plus.com/
Jul 20 '05 #2

P: n/a
"Danny@Kendal" <da***@STOPSPAMghpkendal.co.uk> wrote:
I have a small <div> element which contains two text blocks - one within
<h5> tags and the other within <p> tags.
I don't want any extra line spacing between elements so use the
display:inline property.


Bad move, remove it and the <br>, use the margin and padding property to
adjust space.

Google for a good tutorial on CSS, as you seem to have wrong ideas about
this rather basic stuff.

--
Spartanicus
Jul 20 '05 #3

P: n/a
"Spartanicus" <me@privacy.net> wrote in message
news:vb********************************@news.spart anicus.utvinternet.ie...
"Danny@Kendal" <da***@STOPSPAMghpkendal.co.uk> wrote:
I have a small <div> element which contains two text blocks - one within
<h5> tags and the other within <p> tags.
I don't want any extra line spacing between elements so use the
display:inline property.


Bad move, remove it and the <br>, use the margin and padding property to
adjust space.


Ya fekin beauty! :-)

..infoBody{font-size:10px; margin:0}
..infoHead{font-size:12px; margin:0}

That works exactly how I want it to across all 3 browsers I use.

I usually use www.w3school.com for looking up how to do things.
Good? Bad? Know ye of anything better?
Jul 20 '05 #4

P: n/a
"Mark Tranchant" <ma**@tranchant.plus.com> wrote in message
news:41*********************@ptn-nntp-reader04.plus.net...
Danny@Kendal wrote:
I have a small <div> element which contains two text blocks - one within
<h5> tags and the other within <p> tags.
I don't want any extra line spacing between elements so use the
display:inline property.


Your problem is not block or inline positioning, but browser-default
margin and padding. Add:

margin: 0; padding: 0;

to each element styling and see them come together. Adjust as required -
try putting coloured borders around each element to see the effect.
margin and padding *must* have a unit of measure if non-zero.


Thanks.
Had to remove the "display:inline" and <br> before the margin setting had
any effect on vertical spacing.

Thanks for the tips of font settings too.
Jul 20 '05 #5

P: n/a
Danny@Kendal wrote:
I usually use www.w3school.com for looking up how to do things.
Good? Bad? Know ye of anything better?


http://www.w3.org/TR/REC-CSS1 (CSS 1)
http://www.w3.org/TR/CSS21/ (CSS 2.1)

The definitive reference.

--
Mark.
http://tranchant.plus.com/
Jul 20 '05 #6

P: n/a
On Fri, 6 Aug 2004 12:51:20 +0100, Danny@Kendal
<da***@STOPSPAMghpkendal.co.uk> wrote:
"Spartanicus" <me@privacy.net> wrote in message
news:vb********************************@news.spart anicus.utvinternet.ie...
"Danny@Kendal" <da***@STOPSPAMghpkendal.co.uk> wrote:
>I have a small <div> element which contains two text blocks - one

within
><h5> tags and the other within <p> tags.
>I don't want any extra line spacing between elements so use the
>display:inline property.


Bad move, remove it and the <br>, use the margin and padding property to
adjust space.


Ya fekin beauty! :-)

.infoBody{font-size:10px; margin:0}
.infoHead{font-size:12px; margin:0}

That works exactly how I want it to across all 3 browsers I use.

I usually use www.w3school.com for looking up how to do things.
Good? Bad? Know ye of anything better?


w3schools does state that HTML should not be used for presentation, but
simply to describe the content for the browser to render. Your
presentational ideas are best suggested via CSS.

BTW, px and pt are poor choices for font size on the web. These sizes may
be illegible for many users and unchangeable on many UAs. Best practice -
use 100% for smallest text meant to be legible, and smaller ONLY for
legalese and other content not meant to be read by the common user.
Jul 20 '05 #7

P: n/a
"Danny@Kendal" <da***@STOPSPAMghpkendal.co.uk> wrote in message
news:9a********************@eclipse.net.uk...
I have a small <div> element which contains two text blocks - one

within.....
<snip>
Cheers to everyone for the help and hints.
Off on holiday for a week now. Will look at font sizing when I return.
Jul 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.