SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: Floating Image Affect DIV Height

  1. #1
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    672
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Floating Image Affect DIV Height

    Hi guys

    The latest CSS to baffle me is as follows: I've got a DIV that has a very small amount of text on the left, and an image that floats on the right. The image size varies (though I'm restricting the width) and I need the entire DIV to become the height of the image. At present, the images all stack on top of each other on the right and the text on top of each other on the left. The text becomes further and further separated from the associated images as you go further down the page.

    Without fixing a DIV height, is there a way to get the text to start at the same height as the image, only to the left?

    I have considered putting it in a table, just because I know it will work that way, but the site is for someone else and she won't be able to read through the HTML and maintain it properly that way.

    Cheers in advance guys

  2. #2
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,468
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Stick the image inside the DIV, then contain the text inside a P element, and float the image to the right. You may also want to consider floating the paragraph as well (but to the left).

  3. #3
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    672
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That's kinda what I've done already so I probably don't understand what you're getting at.

    Code:
        <div>
            <a href="#">
                <img src="images/DSCF6334.JPG" class="imageclass" border="0" align="right" />
                <h3>Header</h3>
                <p>Comments</p>
            </a>
        </div>
    What would you change? I tried setting the imageclass to float right but it seems to do the same thing as using align="right"

    For the time being, I'm just setting the div to have the height of the image which works, but it's not ideal
    Last edited by Antnee; Dec 16, 2007 at 07:39.

  4. #4
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,468
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Take the heading and paragraph outside of the anchor. Anchors are inline elements and thus cannot contain block-level elements.

  5. #5
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    672
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    OK, I do that and it's exactly the same (I even removed the anchor completely), the small amount of text is all bunched up under each other and the much larger images are one on top of the other on the right. I need to just get the image to sit on the right as if it were in a separate table cell and the text be aligned to the top of the left cell, but with CSS if possible

  6. #6
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,468
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tell you what. It's getting late for me (despite being past 9am - I've been up nights lately), so why don't you post a picture of how you want it to look and I'll see what CSS magic I can work, ok?

  7. #7
    The CSS Clinic is open silver trophybronze trophy
    SitePoint Award Recipient Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    37,776
    Mentioned
    99 Post(s)
    Tagged
    3 Thread(s)
    Hi,

    Do you mean something like this:

    http://www.pmob.co.uk/temp/caption30.htm

  8. #8
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    672
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yes Paul, as usual, that's pretty much bang on, only I need invisible borders etc. I'll take a look at your CSS if you don't mind and see what I can use from it.

    Thanks, AGAIN! (Don't know why I don't have a personal line straight to you TBH!)

    Dan, thanks for your input, sorry I couldn't be specific enough for you to help any more

  9. #9
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,468
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's ok, Antnee. Like I said, it was getting late for me (as much as I can't stand it, I've been sleeping during the day again).

  10. #10
    The CSS Clinic is open silver trophybronze trophy
    SitePoint Award Recipient Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    37,776
    Mentioned
    99 Post(s)
    Tagged
    3 Thread(s)
    Off Topic:


    Quote Originally Posted by Dan
    as much as I can't stand it, I've been sleeping during the day again
    Dan you need to slow down a bit or you'll burn out. I'll let you have Christmas Day off


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
  •