CSS create padding before line-break

前端 未结 6 1440
说谎
说谎 2020-12-13 04:18

Is it possible to add padding before line-break? As in, making from this \"enter to this

6条回答
  •  萌比男神i
    2020-12-13 05:14

    It took some tryouts, but here it is: the single- and multi-line highlighter with additional padding.

    HTML:

    Welcome to guubo.com, Gajus Kuizinas

    So far you have joined: Networks guubo.com

    CSS:

    h3 {
      padding-left: 5px;
    }
    p {
        background: #0058be;
        position: relative;
        padding: 0 5px;
        line-height: 23px;
        text-align: justify;
        z-index: 0;
    }
    p span {
        background: #fff;
        padding: 2px 0 2px 5px;
        position: relative;
        left: -5px;
    }
    p em {
        background-color: #0058be;
        color: #fff;
        padding: 2px 5px;
    }
    ins {
        position: absolute;
        width: 100%;
        line-height: 23px;
        height: 23px;
        right: -5px;
        bottom: 0;
        background: #fff;
        z-index: -1;
    }
    

    The trick is to style the whole paragraph with a blue background, and only put white background on top of that at the beginning and the end. Doing so assures blue background elsewhere...;)

    Two main disadvantages:

    • The highlighted text has to start at the first line (but does not necessarily have to flow into a second),
    • The paragraph has to be aligned with justification.

    Tested in Opera 11, Chrome 11, IE7, IE8, IE9, FF4 and Safari 5 with all DTD's.

    See edit history for the previous less successful attempts.

提交回复
热议问题