Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text highlighting (label effect) using CSS

Tags:

css

typography

I want to create a text style similar to a label. Looky here:

enter image description here

I can nearly do it using just: http://jsfiddle.net/STApE/

p{display: inline; background: yellow;}

BUT, I want to add some padding. When I do, things go downhill. Same happens if I add a border: http://jsfiddle.net/JN72d/

Any ideas on a simple way to achieve this effect?

like image 419
theorise Avatar asked Feb 04 '11 14:02

theorise


People also ask

How do you make a highlight effect in CSS?

How Do I Highlight Text In CSS? To Highlight text in HTML you have to use an inline element such as the <span> element and apply a specific background style on it. This will create the highlighting effect, which you can tweak in many different ways to create different looks.

How do you change the color of highlights in CSS?

To change the color of the highlighted-text, simply target the ::selection selector and then define the color of the background property.

How do I write text in a label in CSS?

Use a pseudo-selector ( label[required] ) to choose all labels that are required, then add content ( content: "*"; ) after ( ::after ) the element's content. Save this answer.


2 Answers

I was able to achieve it by modifying your DOM structure a bit:

http://jsfiddle.net/Zp2Cm/2/

like image 93
Stephen Avatar answered Oct 23 '22 04:10

Stephen


Wrap each line with a span. Set the span to be block-level. Apply background and padding to span.

like image 34
Chris Avatar answered Oct 23 '22 04:10

Chris