CSS: highlighted text effect

后端 未结 5 1002
一个人的身影
一个人的身影 2021-01-13 17:48

I\'m trying to produce a highlighted text effect with a bit of padding, but the padding is only applied to the beginning and end, not new lines.

#highlight {         


        
相关标签:
5条回答
  • 2021-01-13 18:32

    Try setting the display on your span to inline-block:

    #highlight {
        background: rgba(255, 230, 0, 0.5);
        padding: 3px 5px;
        margin: -3px -5px;
        line-height: 1.7;
        border-radius: 3px;
        display:inline-block;
    }
    

    jsFiddle example

    0 讨论(0)
  • 2021-01-13 18:34

    Solution is this CSS:

    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    display: inline;
    

    https://css-tricks.com/almanac/properties/b/box-decoration-break/

    0 讨论(0)
  • 2021-01-13 18:40

    You need to set the display to inline-block or block.

    #highlight {
        display: inline-block;
        /* ... */
    }
    
    0 讨论(0)
  • 2021-01-13 18:41

    If you're not limited to a specific HTML standard, you could take a look at the <mark> tag, which was introduced with HTML5. This site gives you a quick overlook.

    Hope it helps!

    0 讨论(0)
  • 2021-01-13 18:42

    In case anyone is still looking for an answer:

    p {
        box-shadow: 0px 0px 0px 5px yellow;
        display: inline;
        line-height: 2;
        margin: -5px -5px;
        background-color: yellow;
        border-radius: 1px;
    }
    

    See jsfiddle here.

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