CSS Line Break Bug (screencast)

 

While working on a client site this week, I came across a very strange bug that I just felt needed to be shared. It appears to happen when an inline element is within another inline element. The simple way to fix this error is to clump your elements together and avoid any line breaks or code indenting. Watch the following video for further information!

Download Source Files

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Add to favorites
  • Design Float
  • DZone
  • email
  • FriendFeed
  • PDF
  • Propeller
  • Reddit
  • RSS
  • StumbleUpon
  • Twitter

Related posts:

  1. CSS/JavaScript Hover Menu (screencast)
  2. Creating Semantic CSS Navigation
  3. CSS or Tables for layout?
  4. CRAP Design actually good?
  5. Squish the Internet Explorer Z-Index Bug


Written by Brenley Dueck

 

13 Responses to “CSS Line Break Bug (screencast)”

  1. Gopal Raju Says:

    April 17th, 2009 at 11:31 pm

    Nice Solution!

    Gopal Raju
    productivedreams.com
    twitter.com/gopalraju

  2. Praveen Vijayan Says:

    April 18th, 2009 at 2:37 am

    Thanks to point out this issue

    This type of issue happen in ie when there is a gap between img tag and its preceding or succeeding element.

    eg:

    a white gap will show in ie between image and div. The following will eliminate this white gap.

  3. Meshach Says:

    April 18th, 2009 at 11:03 am

    Thanks, this is very helpful.

  4. shane sponagle Says:

    April 18th, 2009 at 2:24 pm

    Cool tip. Don’t remember having this problem before, but now I am ready for it if it does show up. Thanks

  5. Ian Says:

    April 20th, 2009 at 9:41 am

    You really probably shuldn’t convert the elements to inline, because then you lose all sorts of support for margins and padding. As well making your code clump up makes it less pleasant to work with.

    A more elegant solution is to set the elements to Float: left/right and adjust from there. You can even set the list items to float and the anchors to display: block for maximum control.

    The float option does have some of its own pitfalls, but as long as you apply them carefully and use clear: both on your contrainer blocks you will be fine.

  6. Paperboy Says:

    April 21st, 2009 at 12:54 pm

    I remember having these problems (with images) too. And it sure took a while before I found the solution!

    Thanks for the reminder!

  7. Snookerman Says:

    April 21st, 2009 at 4:08 pm

    This is not a bug. If you have a line break or a lot of whitespace between inline elements, the browser will only show one space. That is why you should put anchor tags right after each other or image tags. If you make list items or divs act like inline elements, they will follow the same rules.

  8. Snookerman Says:

    April 21st, 2009 at 4:18 pm

    This is a better explanation maybe, if you put two anchor links after each other in a text, for example site site you expect the space between them to be rendered, and it is. If you put more than one space, or like in your example, a line break and some tabs, the browser will still only display a space and ignore the rest. It even happens in normal text. This:
    hello hello
    is the same as:
    hello hello

    You can try it in your examples, leave only one space between the problematic elements and you will see the same space.

    This is definitely not a bug, it’s just expected behaviour that you have totally misunderstood.

  9. Snookerman Says:

    April 21st, 2009 at 4:20 pm

    In the above example I actually had a lot of space between the first two hellos and only one space between the second pair. The browser immediately ignored all spaces except one. Just as expected.

  10. Brenley Dueck Says:

    April 21st, 2009 at 4:29 pm

    Good tips snookerman… I don’t really have all the answers… but wanted to point out the problem anyways.

  11. kevinMario Says:

    April 21st, 2009 at 9:15 pm

    Use SHIFT+CTRL+J in Dreamweaver and ‘fold’ your code as often as you can, make sure spaces between the codes are all white (e.g no blue spaces)

    The easiest way to do this is to fold your BODY tag and then inspect your code. The cleaner it looks the better it is.

    I’ll post a screenshot to show you what i mean in a sec

  12. kevinMario Says:

    April 21st, 2009 at 9:23 pm

    Hope this could explain better :
    http://www.lunarist.com/files/line_bug_solution.jpg

    Then again I have to concur to one of the posters above for you just to set LI elements to float:Left and set the UL to overflow:hidden ( float container trick ) and everything should be sweet.

  13. Joseph S. Says:

    April 22nd, 2009 at 9:51 am

    Yeah, Snookerman, that’s what I thought immediately. When you leave a space in your code between inline elements it will be rendered as one space… just as if you placed a bunch of nbspc between them it would add extra spaces. It is the idea in our head of how li elements should behave as block level that would make this behavior unexpected.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 
connect with me!