pretty html highlighting using <span>

柔情痞子 提交于 2019-12-10 18:14:40

问题


I'm highlighting text in a HTML document using <span> tags around the content to be highlighted. The span class has a background-color defined, and a border-radius is also set. This works well.

I'd like the highlight to extend a bit further beyond the normal extents of the <span> content. That is, a few pixels to the left of the span-start, and a few pixels to the right of the span-end. Ideally I'd do this without spacing apart the content itself.

Any good css tricks I can use to achieve this?


回答1:


You can set a padding and a negative margin. For example:

span {
    margin: -5px;
    padding: 5px;
}

You can see a demo here.




回答2:


margin: 10px 0px; ??

if this does not solve your issue can you elaborate on the problem ?



来源:https://stackoverflow.com/questions/5149542/pretty-html-highlighting-using-span

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!