Results 1 to 3 of 3

Thread: Why does text overlap in this example

  1. #1
    Join Date
    Jul 2005
    Posts
    101
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Why does text overlap in this example

    The following example is from w3schools:

    Code:
     
    <html>
    <head>
    <style type="text/css">
    img.normal
    {
    height:auto;
    }
    img.big
    {
    height:120px;
    }
    p.ex
    {
    height:100px;
    width:50px;
    }
    </style>
    </head>
    
    <body>
    <img class="normal" src="logocss.gif" width="95" height="84" /><br />
    <img class="big" src="logocss.gif" width="95" height="84" />
    <p class="ex">The height and width of this paragraph is 100px.</p>
    <p>This is some text in a paragraph. This is some text in a paragraph. This is some text in a paragraph. This is some text in a paragraph. This is some text in a paragraph. This is some text in a paragraph.</p>
    </body>
    </html>
    If I change the width of selector p.ex to 50, then the sentence overlaps the paragraph that follows. Why does this happen?
    Cheers
    Billy

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    this has to do with the "overflow" property, which is (by default) "auto." What that means depends on the browser, though "scrollbars if necessary" is recommended.

    Apparently, however, in both Fx and Chrome (haven't tested in any others), the default value for paragraphs is "visible." Try it; overflow: visible will produce the same result (while overflow: auto will produce scrollbars). The second paragraph is overlapping the first because it is positioned at the bottom of the first (50px tall) paragraph (so it's actually the first paragraph that is "under-lapping" the second).

    If you want to control this, you need to:
    a) choose an overflow value that will prevent it, such as overflow: hidden or overflow-x: visible
    b) not apply a set height to your paragraph (that's kind of an odd example anyway; it makes more sense to apply the height to a <div> that contains the paragraph).

  3. The Following User Says Thank You to traq For This Useful Post:

    wkenny (12-16-2010)

  4. #3
    Join Date
    Jul 2005
    Posts
    101
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the excellent explanation. I should point out that the code sample above shows my width of 50px. The original code had width of 100px.
    Cheers
    Billy

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •