CSS: highlighted text effect

孤街醉人 提交于 2019-12-01 04:15:11

问题


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 {
background: rgba(255,230,0,0.5);
padding: 3px 5px;
margin: -3px -5px;
line-height: 1.7;
border-radius: 3px;
}

<span id=highlight>text<br>here</span>

Please see here: http://jsfiddle.net/CNJZK/7/

Are there any pure-CSS fixes to get the internal ("sharp") edges to extend a bit farther? i.e. like in this image: http://i.imgur.com/j8mIJZS.jpg


回答1:


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




回答2:


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!




回答3:


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

#highlight {
    display: inline-block;
    /* ... */
}



回答4:


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.




回答5:


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/



来源:https://stackoverflow.com/questions/18746649/css-highlighted-text-effect

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