I have always avoided using the CSS width
property (including max-width
/ min-width
) on text elements, such as h1
, h2
, h3
, p
etc. Instead, I will set widths on containing, block level elements (such as a div
).
However, I do this out of intuition or something I once learned, but I can't find any specification as to whether this is correct or not. Am I just making this up, or is there some kind of CSS/HTML specification that lays this out?
Or, am I just confusing h1
etc with inline elements (eg. span
), where width has no effect?
Can I do this:
<style>
.custom-class {
width: 500px;
}
</style>
<h1 class="custom-class">Test</h1>
Or should I do this?
<style>
.custom-class {
width: 500px;
}
</style>
<div class="custom-class">
<h1>Test</h1>
</div>