Problem with line spacing when using display:inline

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Danny@Kendal

    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{pos ition:absolute; top:50px; left:50px; width:90px; height:100px;
    background:cyan ; text-align:center}
    // -->
    </style>
    </head>

    <body>

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

    </body>
    </html>



  • Mark Tranchant

    #2
    Re: Problem with line spacing when using display:inline

    Danny@Kendal wrote:
    [color=blue]
    > 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.[/color]

    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.

    Comment

    • Spartanicus

      #3
      Re: Problem with line spacing when using display:inline

      "Danny@Kend al" <danny@STOPSPAM ghpkendal.co.uk > wrote:
      [color=blue]
      >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:inli ne property.[/color]

      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

      Comment

      • Danny@Kendal

        #4
        Re: Problem with line spacing when using display:inline

        "Spartanicu s" <me@privacy.net > wrote in message
        news:vbq6h01r35 l2jsqhopqaidok7 7brp2a6t8@news. spartanicus.utv internet.ie...[color=blue]
        > "Danny@Kend al" <danny@STOPSPAM ghpkendal.co.uk > wrote:
        >[color=green]
        > >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:inli ne property.[/color]
        >
        > Bad move, remove it and the <br>, use the margin and padding property to
        > adjust space.[/color]

        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?


        Comment

        • Danny@Kendal

          #5
          Re: Problem with line spacing when using display:inline

          "Mark Tranchant" <mark@tranchant .plus.com> wrote in message
          news:4113633e$0 $521$ed2e19e4@p tn-nntp-reader04.plus.n et...[color=blue]
          > Danny@Kendal wrote:
          >[color=green]
          > > 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.[/color]
          >
          > 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.[/color]

          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.


          Comment

          • Mark Tranchant

            #6
            Re: Problem with line spacing when using display:inline

            Danny@Kendal wrote:
            [color=blue]
            > I usually use www.w3school.com for looking up how to do things.
            > Good? Bad? Know ye of anything better?[/color]

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

            The definitive reference.

            --
            Mark.

            Comment

            • Neal

              #7
              Re: Problem with line spacing when using display:inline

              On Fri, 6 Aug 2004 12:51:20 +0100, Danny@Kendal
              <danny@STOPSPAM ghpkendal.co.uk > wrote:
              [color=blue]
              > "Spartanicu s" <me@privacy.net > wrote in message
              > news:vbq6h01r35 l2jsqhopqaidok7 7brp2a6t8@news. spartanicus.utv internet.ie...[color=green]
              >> "Danny@Kend al" <danny@STOPSPAM ghpkendal.co.uk > wrote:
              >>[color=darkred]
              >> >I have a small <div> element which contains two text blocks - one[/color]
              >> within[color=darkred]
              >> ><h5> tags and the other within <p> tags.
              >> >I don't want any extra line spacing between elements so use the
              >> >display:inli ne property.[/color]
              >>
              >> Bad move, remove it and the <br>, use the margin and padding property to
              >> adjust space.[/color]
              >
              > 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?[/color]

              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.

              Comment

              • Danny@Kendal

                #8
                Re: Problem with line spacing when using display:inline

                "Danny@Kend al" <danny@STOPSPAM ghpkendal.co.uk > wrote in message
                news:9aednWE01K u8w47cRVn-pg@eclipse.net. uk...[color=blue]
                > I have a small <div> element which contains two text blocks - one[/color]
                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.


                Comment

                Working...