Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make the width of a container <p> tag match the width of the <span> it contains?

Tags:

html

css

I have a paragraph that contains a span. The <p> tag's width is much wider than the <span> it contains, but I would like it to be only as large as its child <span>.

<p>
    <span>Some text.</span>
</p>

I tried width: auto but that doesn't seem to work.

like image 686
Jackmc1047 Avatar asked Feb 14 '23 08:02

Jackmc1047


1 Answers

use display:inline-block; with p element.

p{
    display:inline-block;
}

Js Fiddle Example

like image 142
Sachin Avatar answered Feb 16 '23 22:02

Sachin