473,416 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 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 7086
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.