Space between div and img?

后端 未结 4 1046
我在风中等你
我在风中等你 2020-12-14 01:29

I have code like this:

        

1. Orange

some text in here

相关标签:
4条回答
  • 2020-12-14 01:52

    that's because there is whitespace between the tags

    do:

    </div><img class="separator" src="images/separator.png" /> 
    
    0 讨论(0)
  • 2020-12-14 01:57

    I had a 3px gap between an image and div tag. Also all styles were set to 0. Really weird.

    The fix:

    img {
       vertical-align: middle;
    }
    

    This worked beautifully for me.

    0 讨论(0)
  • 2020-12-14 02:00

    With no screenshots to refer to I'm left in the dark on what you want, so this is all guessing.

    I'm guessing from class="separator" that you are trying to break up your content with a horizontal line. Shouldn't you be using <hr /> with appropriate styling if that's the case?

    In any case, note that <p> elements have vertical margins set by default.

    I don't see why you want the separator right up snug against your text, because it visually doesn't make sense to me.

    If you really do, there's a bunch of options:

    1. Set margin-bottom: 0; on the <p>
    2. Set margin-top: -*px; on .separator where you're assuming you're always going to have an element right before the separator with bottom margin of *px
    3. #sc p:last-child { margin-bottom: 0; } and IE9.js for letting older Internet Explorer versions support it

    But I reiterate; no margin between text and a separator doesn't sound right to me.

    0 讨论(0)
  • 2020-12-14 02:03

    Add display: block; to the .separator image.

    .separator {
        margin: 0;
        padding: 0;
        display: block;
    }
    

    The problem is that images can sometimes add a bit of magic space up/below them, I have this issue whenever I'm working with image elements as *block* elements.

    0 讨论(0)
提交回复
热议问题