Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply background color with css to text with line break [duplicate]

Tags:

html

css

I've put it in a jsfiddle to demonstrate: https://jsfiddle.net/og90214y/

I need to set so the background follows the text and not <p> elements width. For that I've set display: inline.

For padding to both sides I've got box-shadow: 45px 0 0 #f00,-45px 0 0 #f00;, but this padding doesn't work on FireFox (works on Chrome), on FireFox it only works for the first line and for the rest there is padding, but without background color on it.

What could I do to make it work on FireFox as well and show padding + background color on those 45px at each end?

like image 910
Xeen Avatar asked Jan 11 '16 11:01

Xeen


People also ask

How do you put a background color on text in CSS?

Simply add the appropriate CSS selector and define the color property with the value you want. For example, say you want to change the color of all paragraphs on your site to navy. Then you'd add p {color: #000080; } to the head section of your HTML file.

How do I set a background color for the width of text?

Put the text in an inline element, such as a <span> . And then apply the background color on the inline element. An inline element is as big as its contents is, so that should do it for you.


1 Answers

add this property box-decoration-break: clone; & remove box-shadow

.slider-text p {
background: #f00 none repeat scroll 0 0;
box-decoration-break: clone;
-webkit-box-decoration-break: clone;
color: #fff;
display: inline;
font-weight: 300;
line-height: 1.4;
margin-bottom: 10px;
padding: 0 20px;
}

https://jsfiddle.net/og90214y/6/

like image 110
Lalji Tadhani Avatar answered Oct 27 '22 14:10

Lalji Tadhani