br line-height in safari and chrome leaving gap

前端 未结 5 573
野性不改
野性不改 2021-01-02 11:38

In my HTML I have a

, and inside the
I need different vertical spacing between lines of text. I\'m achieving this by using
相关标签:
5条回答
  • 2021-01-02 11:48

    This worked for me for both firefox and chrome. Got the idea from @SamuelC and @anushr.

    br{ 
        display: block;
        line-height: 0.1; 
        content: " ";
    }
    
    0 讨论(0)
  • 2021-01-02 11:57

    Those browsers might be reading your white space (carriage return, etc) and propping it open with a  sort of value. I suggest using multiple div tags and style the divs with margin-bottom attributes of the space you want.

    <div style="margin-bottom: 2px">content</div>
    <div style="margin-bottom: 5px">content</div>
    <div>content</div>
    
    0 讨论(0)
  • 2021-01-02 12:01

    Try this:

    br { line-height: 1em; }
    

    or:

    br { margin-top: 2em; }
    
    0 讨论(0)
  • 2021-01-02 12:03

    This worked on Chrome (the content attribute did the trick):

    br {
      content: " ";
      display: block;
      margin: 1em;
    }
    
    0 讨论(0)
  • 2021-01-02 12:06

    I know this is old, but my answer here is cross-browser without turning br into a block

    /* line height can be set to whatever you want*/
    br {line-height: 0.1; content: " "} 
    
    0 讨论(0)
提交回复
热议问题