Vertical alignment of empty inline-block elements

后端 未结 4 1698
情歌与酒
情歌与酒 2020-12-19 04:02

Consider the following html/css:



a


        
相关标签:
4条回答
  • 2020-12-19 04:35

    Just in case still helps someone, another solution, enforcing to have some space from CSS:

      span:empty:before {
        content: "\0020";
        display: inline-block;
      }
    
    0 讨论(0)
  • 2020-12-19 04:36

    Give the span top alignment then negative margin equal to your padding, and you don't need the non-breaking space hack.

    span
    {
        display:inline-block;
        width:5em;
        height:5em;
        padding:1em;
        vertical-align:top;
        margin-top: -1em;
    }
    
    
    
    a
        <span style="background-color:blue;">b</span>
        <span style="background-color:green;"></span>
        <span style="background-color:red;">c</span>
    d
    
    0 讨论(0)
  • 2020-12-19 04:37
    a
    <span style="background-color:blue;">b</span>
    <span style="background-color:green;">&nbsp;</span>
    <span style="background-color:red;">c</span>
    d
    
    0 讨论(0)
  • 2020-12-19 04:38

    Try adding &nbsp; inside of the green colored span.

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