mheavers
mheavers

Reputation: 30168

css - create a block element whose width is only as large as the text contained within

I have this fiddle where there is a rollover style applied to a paragraph - but I want that paragraph to only be as wide as the text contained within (not the entire width of the containing element). If I do display:inline-block it brings each menu option up to the same line but sets the width of each item appropriately. How do I combine both (options on separate lines, but only as wide as the text contained inside)?

http://jsfiddle.net/heaversm/wxqeW/

Upvotes: 0

Views: 288

Answers (3)

henryaaron
henryaaron

Reputation: 6202

You could also have the background color change when you hover the entire <p> Fiddle: http://jsfiddle.net/wxqeW/11/

Upvotes: 1

Gats
Gats

Reputation: 3462

Try applying a

width: auto;

to the css. Also check that the divs are not floating.

Upvotes: 0

Scott
Scott

Reputation: 21890

You could add a span and set the hover state to the span

Fiddle ------> HERE

Upvotes: 2

Related Questions