Making images\divs line up perfectly

  • kc0tma
  • o|||||||o
  • Web Master
  • User avatar
  • Joined: Jul 20, 2007
  • Posts: 3318
  • Loc: Trout Creek, MT
  • Status: Offline

Post January 16th, 2008, 8:02 am

Yesterday I was playing around (nothing important) trying to get a paragraph go around an image. I got that to work ok by putting part of an image as a background for one div, then floated it left. The paragraph occupied the space to the right, then when it got farther down the page than the image, it went full width just like I wanted. But where I have the top half of an image and the bottom half of an image coming together, there is a small gap:

Image

Here is my code:

Code: [ Select ]
<html>
  <head>
    <title>Image testing</title>
    <style type="text/css">
      #container {
        width: 512px;
      }
      #top {
        width: inherit;
        background: white url('top2.png') no-repeat top center;
        height: 200px;
        width: 512px;
      }
      #bottom {
        width: inherit;
      }
      #pic {
        float: left;
        background: white url('bottom.png') no-repeat top center;
        width: 200px;
        height: 133px;
      }
    </style>
  </head>
  <body>
    <div id="container">
      <div id="top"></div>

        <div id="pic"></div>
        <p>Paragraph shortened to make it take up less space in the thread.</p>
        <p>Paragraph shortened to make it take up less space in the thread.</p>
      </div>
  </body>
</html>
  1. <html>
  2.   <head>
  3.     <title>Image testing</title>
  4.     <style type="text/css">
  5.       #container {
  6.         width: 512px;
  7.       }
  8.       #top {
  9.         width: inherit;
  10.         background: white url('top2.png') no-repeat top center;
  11.         height: 200px;
  12.         width: 512px;
  13.       }
  14.       #bottom {
  15.         width: inherit;
  16.       }
  17.       #pic {
  18.         float: left;
  19.         background: white url('bottom.png') no-repeat top center;
  20.         width: 200px;
  21.         height: 133px;
  22.       }
  23.     </style>
  24.   </head>
  25.   <body>
  26.     <div id="container">
  27.       <div id="top"></div>
  28.         <div id="pic"></div>
  29.         <p>Paragraph shortened to make it take up less space in the thread.</p>
  30.         <p>Paragraph shortened to make it take up less space in the thread.</p>
  31.       </div>
  32.   </body>
  33. </html>


What should I do to make that tiny gap go away? It shows in both IE7 and firefox. I'll put my pictures I was using in the kc0tma photobucket page if anyone wants to play.

@celandine: see how ridicuously simple that turned out to be?
Like Mr Spork, I also write about my interest in alcoholic beverages.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post January 16th, 2008, 8:02 am

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Joined: Sep 22, 2003
  • Posts: 6129
  • Loc: Seattle, WA
  • Status: Offline

Post January 16th, 2008, 10:39 am

Play around with the margin and padding. Any by play around with, I mean make them zero. ;)
The Beer Monocle. Classy.
  • kc0tma
  • o|||||||o
  • Web Master
  • User avatar
  • Joined: Jul 20, 2007
  • Posts: 3318
  • Loc: Trout Creek, MT
  • Status: Offline

Post January 16th, 2008, 1:20 pm

No luck with padding and margins. Believe it or not, the gap was actually bigger for a while yesterday, but I had extra divs and junk in there that weren't doing anything, so I remade it and got the results you see above. Looking at the file now, I can't see anything else in there to trim out.

:?:
Like Mr Spork, I also write about my interest in alcoholic beverages.
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Joined: Mar 12, 2007
  • Posts: 6228
  • Loc: South-Africa
  • Status: Offline

Post January 17th, 2008, 2:35 am

try:
Code: [ Select ]
position:relative;
top:-1px;
left:0px;
  1. position:relative;
  2. top:-1px;
  3. left:0px;
Let's leave all our *plum* where it is and go live in the jungle ...
  • kc0tma
  • o|||||||o
  • Web Master
  • User avatar
  • Joined: Jul 20, 2007
  • Posts: 3318
  • Loc: Trout Creek, MT
  • Status: Offline

Post January 17th, 2008, 7:53 am

You know what R_T? That worked. But I noodled up my own graffics. I played around with the pixel values, and it moved the image around, but no matter how far I moved it up it still had that little one pixel white line. Woops...I have a little white stripe on the top of the bottom half of my banana. So I did learn to never use auto crop, always always ALWAYS crop it by hand.

Thanks for your help spork and R_T!
Like Mr Spork, I also write about my interest in alcoholic beverages.
  • kbergmann
  • Expert
  • Expert
  • User avatar
  • Joined: Dec 04, 2007
  • Posts: 659
  • Loc: USA
  • Status: Offline

Post January 17th, 2008, 8:25 am

Good to know. I tend to crop by hand as is, but will stay away from auto cropping. You learn something new every day.
  • neksus
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Sep 10, 2004
  • Posts: 2194
  • Loc: Canada
  • Status: Offline

Post April 1st, 2008, 9:01 pm

Some browsers will also display the gap because your tags aren't touching.
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post April 1st, 2008, 10:24 pm

So I take it that this is fixed now... right?
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • neksus
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Sep 10, 2004
  • Posts: 2194
  • Loc: Canada
  • Status: Offline

Post April 2nd, 2008, 7:22 am

I think he had a space in his actual image and it was unrelated to the code lol

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 138 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.