472,782 Members | 1,274 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,782 software developers and data experts.

Problem with line spacing when using display:inline

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
7 7053
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
"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
"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
"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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Timo Nentwig | last post by:
Hi! Is it a HTML engine bug or can somebody tell me how I use border: collapse; with li { display: inline; border: solid 1px gray; }
4
by: Axel Dahmen | last post by:
Hi, current browsers don't support "display: inline-block;" and "display: inline-table;", resp. Thus I'm using "float: left;" to achieve a similar effect. Problem is that if a row of elements...
23
by: Mat | last post by:
<div id="container"> <div id="main"> <div id="header"> <p class="Address">123 Fake Street, </p> <p class="City">Crazy City, </p> <p class="Province">Ontario </p> <p class="PostalCode">H0H...
0
by: dotnet | last post by:
I am trying to make a page that is changing the page schema(colors and graphics) depends on the specific value (for example, test.aspx?page=1) I have so far achieved accepting page values (with...
2
by: Showjumper | last post by:
Is there a peformance hit when using inline code? As an example, lets i store a user's preferences for backgtound color of a page. When he/she logs in, i stick the color value into their session...
1
by: itaitai2003 | last post by:
I'm attempting to configure the DISPLAY attribute using inline code but without success. (I don't want to use the Panel) Any ideas? <div id="panel" style="DISPLAY: <%# GetDisplayStatus() %> ">...
4
by: txican | last post by:
the HTML is: ---------------------------------------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html> <head> <title>foo</title>...
5
by: CES | last post by:
All, I was hoping that someone might be able to help me with a few questions on Aligning Block Elements properly... Basically I have a row that has a fixed width of 900px. Within the row their is...
12
by: Vadim Guchenko | last post by:
Hello. I'm using the following code: <html> <head> <style type="text/css"> pre {display: inline;} </style> </head>
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.