The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Can float img have margin-bottom if there’s text below but not if there isn’t?

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #143908

    I have an image floating left in a box with margins 0 1em 0.5em 0, which is to say flush left and top, or bleed, if you prefer. Sometimes text will be long enough to flow below the image, sometimes not. When text flows below the image, of course I want to keep that bottom margin, but when the text does not I’d love to have the bottom of the box come up to be flush with the image.

    So from the image’s point of view I’d like to have that bottom margin apply against text but not against the box. Or from the text’s point of view I’d like some version of margin-top to apply even above the full-width section of text.

    I have an example with flow-below text here; no-flow-below here. The first example works just fine. In the latter case I’d like the box to come up flush to the bottom of the image. Is there a way to do that?


    Off the top of my head, sounds like a javascript thing. Check if the height of the containing element >= the height of the image and add bottom padding if true.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘CSS’ is closed to new topics and replies.