SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: DIV code produces line breaks - how to fix?

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DIV code produces line breaks - how to fix?

    Ok what CSS do I need to add to fix line breaks in DIV code? Here's what I'm trying to do: I want to create an image that is sliced in DIVs. It's a 3 columns 3 row slice. So, I create code like so, but every row has a break that creates spaces between the row of images (the columns don't have any problems). What am I doing wrong? And what CSS do I need to use to fix it? Here's a sample of the code:

    Code HTML4Strict:
    <div>
    <img src="image name.jpg" width="100" height="100" border="0" alt="image name">
    <img src="image name2.jpg" width="100" height="100" border="0" alt="image name">
    <img src="image name3.jpg" width="100" height="100" border="0" alt="image name">
     
    <!-- This is where the line break between rows of images occurs even though no <br>s are used -->
     
    <img src="image name4.jpg" width="100" height="100" border="0" alt="image name">
    <img src="image name5.jpg" width="100" height="100" border="0" alt="image name">
    <img src="image name6.jpg" width="100" height="100" border="0" alt="image name">
     
    <!-- This is where the line break between rows of images occurs even though no <br>'s are used -->
     
    <img src="image name4.jpg" width="100" height="100" border="0" alt="image name">
    <img src="image name5.jpg" width="100" height="100" border="0" alt="image name">
    <img src="image name6.jpg" width="100" height="100" border="0" alt="image name">
    </div>

    Each row of images horizontally is fine - there are no breaks in the images. But going from one row to the next, there are. How to fix?

  2. #2
    It's all Geek to me silver trophybronze trophy
    SitePoint Award Recipient ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, Australia
    Posts
    19,958
    Mentioned
    216 Post(s)
    Tagged
    2 Thread(s)
    You probably just need to add this to the CSS:

    Code:
    img {vertical-align: bottom}
    That's because images, by default, align with the baseline of any text that might sit beside them, leaving room below for the descenders.

    Any reason why you are slicing the image up? You probably don't need to do that.

  3. #3
    Community Advisor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,138
    Mentioned
    34 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by WebDesignGeek972 View Post
    Ok what CSS do I need to add to fix line breaks in DIV code? Here's what I'm trying to do: I want to create an image that is sliced in DIVs. It's a 3 columns 3 row slice. So, I create code like so, but every row has a break that creates spaces between the row of images (the columns don't have any problems). What am I doing wrong? And what CSS do I need to use to fix it? Here's a sample of the code:


    Each row of images horizontally is fine - there are no breaks in the images. But going from one row to the next, there are. How to fix?
    You could also try font-size: 0px or float: left - both work:

    HTML Code:
    <style type='text/css'>
      #fred {width:330px; height:420px; outline:solid 1px #f00; font-size: 0px}
      #fred img {float:left; width:100px; height:100px; border:0; margin:0px; padding:0}
    </style>  
    </head>
    <body>
    
    <div id='fred'>
      <img src="http://subdomain.localhost/thumb/chain_letter_thumb.jpg"  alt="image name" />
      <img src="http://subdomain.localhost/thumb/chain_letter_thumb.jpg"  alt="image name" />
      <img src="http://subdomain.localhost/thumb/chain_letter_thumb.jpg"  alt="image name" />
      <img src="http://subdomain.localhost/thumb/chain_letter_thumb.jpg"  alt="image name" />
      <img src="http://subdomain.localhost/thumb/chain_letter_thumb.jpg"  alt="image name" />
      <img src="http://subdomain.localhost/thumb/chain_letter_thumb.jpg"  alt="image name" />
      <img src="http://subdomain.localhost/thumb/chain_letter_thumb.jpg"  alt="image name" />
      <img src="http://subdomain.localhost/thumb/chain_letter_thumb.jpg"  alt="image name" />
      <img src="http://subdomain.localhost/thumb/chain_letter_thumb.jpg"  alt="image name" />
    /div>
    Last edited by John_Betong; May 11, 2012 at 06:50. Reason: changed font-size to 0px

  4. #4
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,564
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Font-size:0 dooesn't work in Opera, just so you know, ify ou pick that option .
    Twitter-@Ryan_Reese09
    http://www.ryanreese.us -Always looking for web design/development work

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    You probably just need to add this to the CSS:

    Code:
    img {vertical-align: bottom}
    That's because images, by default, align with the baseline of any text that might sit beside them, leaving room below for the descenders.

    Any reason why you are slicing the image up? You probably don't need to do that.
    Thank you Ralph! Vertical-align worked. I'm looking into the image map option for the image but it results in the image being huge - over 120 kB.

  6. #6
    It's all Geek to me silver trophybronze trophy
    SitePoint Award Recipient ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, Australia
    Posts
    19,958
    Mentioned
    216 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by WebDesignGeek972 View Post
    I'm looking into the image map option for the image but it results in the image being huge - over 120 kB.
    So the purpose of this is to have different parts of the image clickable?

  7. #7
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    So the purpose of this is to have different parts of the image clickable?
    Yes.

  8. #8
    It's all Geek to me silver trophybronze trophy
    SitePoint Award Recipient ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, Australia
    Posts
    19,958
    Mentioned
    216 Post(s)
    Tagged
    2 Thread(s)
    Image maps are a bit old hat. A nice way to do this is with a sprite image. E.g.

    http://www.noobcube.com/tutorials/ht...inners-guide-/

    What you need is much simpler than the one in that example.

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
  •