CSS: Background-color on multi-line text?

前端 未结 7 1333
离开以前
离开以前 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 06:06

    Getting it perfect with pure CSS is difficult and only achievable under certain conditions. For example, if you use breaks and set the line-height to big, you'll see gaps in between. And what about the padding around the sides?

    Also, you'll need spans and that will just uglify your markup.

    Luckily Sam Croft came up with a simple jQuery plugin to counter this. It's quick, light and works under most conditions.

    Article: http://samcroft.co.uk/2011/jquery-plugin-for-inline-text-backgrounds/

    Demo: http://samcroft.co.uk/demos/inline-backgrounds/

    Source: https://github.com/samcroft/css-inline-backgrounds/blob/master/inline-backgrounds.js

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