Breaking to a new line with inline-block?

前端 未结 8 787
梦如初夏
梦如初夏 2021-01-30 15:45

I want to remove the
\'s and do the break lines through CSS. If I change the spans to display:block the width will go 100% and I need the w

相关标签:
8条回答
  • 2021-01-30 16:36

    Here is another solution (only relevant declarations listed):

    .text span {
       display:inline-block;
       margin-right:100%;
    }
    

    When the margin is expressed in percentage, that percentage is taken from the width of the parent node, so 100% means as wide as the parent, which results in the next element getting "pushed" to a new line.

    0 讨论(0)
  • 2021-01-30 16:37

    use float: left; and clear: left;

    http://jsfiddle.net/rtM6J/

    .text span {
       background: rgba(165, 220, 79, 0.8);
       float: left;
       clear: left;
       padding: 7px 10px;
       color: #fff;
    }
    
    0 讨论(0)
提交回复
热议问题