CSS: Background-color on multi-line text?

前端 未结 7 1342
离开以前
离开以前 2020-12-09 05:27

Do you have an idea to add a \"background-color\" property on a multi-line text, with two difficulties:

  • Background must stop after the last word of each line
7条回答
  •  我在风中等你
    2020-12-09 05:47

    The box-shadow solution as shown by @gabitzish stopped working properly in IE11 and FF34+ (released 09-2014).

    You can add box-decoration-break:clone; to make it work in IE11 and FF34+ too:

    p {
        display: inline;
        padding: 0.5em 0em;
        background-color: #FFAA3B;
        box-shadow: 1em 0 0 #FFAA3B, -1em 0 0 #FFAA3B;
        box-decoration-break: clone;
    }
    

    Works in Webkit, Firefox, IE9+ with proper prefixes.

    Demo : http://jsfiddle.net/cLh0onv3/1/

    Note: Already stated this elsewhere.

提交回复
热议问题