If I make an <h1>
title, its width is set to 100% by default. Is there a way to make sure its width is set to the smallest value possible? I need this to do special CSS stuff with borders.
views:
121answers:
3
+8
A:
You can give it display: inline
, this will make it behave like any text element (The default for h1
is display: block
). There are other ways - float: left
for example - , but I find this the simplest and the one with the fewest side effects.
Note that you will then probably have to add a <br>
to ensure a line break after the h1.
Pekka
2010-01-23 19:15:51
or <br/> if it's XHTML. (No need to use float:left I think...)
Dan
2010-01-23 19:44:02
+3
A:
It's a block level element, so it follows the rules of display:block
. You can set display:inline
, which may do what you need or not, depending on the context.
troelskn
2010-01-23 19:16:42
+3
A:
Instead of display: inline
, give it display: inline-block
. This will retain the block-like qualities of the h1 tag, except for the 100% width.
DaveS
2010-01-23 19:42:51