The div
is the quintessential block level element, and the span
is the inline counterpart. They are the simplest possible form of that display type, with no other properties. In a great many cases I will give either of them the style:
display: inline-block;
This makes them behave in a very handy way. For div
it means boxes that will easily sit next to each-other, while maintaining their width and height as defined. For the span
I can use this to make colorful rectangles. The inline-block
display is great for so many things, but I have never seen an element that starts as an inline-block
without anything else going on.
Images (img
) are, but they are obviously not suited for the same things as a div
, they have that style, but they fulfill a different purpose.
So is there an element that I don't know of that is the quintessential inline-block
, or is this left out?
And if not, why? The uses of inline-block
are numerous, so it seems like there should be some element that takes that basic form.
There's no such element, and there are some good reasons why not.
inline-block
has several uses in contemporary web design. However it is not part of the original design, which only includes block and inline elements. Instead it derives from <img>
as added by NSCA Mosaic. (Which uses the wrong markup and helped defeat the original "responsive design". I think we've only just started to fix the problems with img).
Further down the timeline, inline-block
still wasn't part of IE4 or 5, or any version of Netscape. It wasn't part of the early HTML4 era. So we wouldn't expect to find your hypothetical element in that version of the standard. inline-block
only appears in CSS2, which came after HTML4. (Look at the reference section in each standard).
Unlike block
, inline-block
is affected by whitespace in the markup. It's implied by the name, and it's what you'd expect from looking at <img>
in the middle of some text (aka wordprocessor object anchored "as character"). But beyond its origins there, the whitespace-dependent markup soon becomes very troublesome. I wouldn't expect W3C HTML5 to enshrine this in a new element.
Specifying it would certainly involve argument about "semantics", separation of content and presentation etc. (As well as what to call it :). And if the default rendering makes whitespace significant - is that not part of the semantics of that element? Consider using images to represent words - or individual letters of a word (with appropriate alt text). This illustrates that the presence of whitespace (or not) around this element would be semantically significant, just like the presenceofwhitespaceseparatingwordsissemanticallysignificant. That seems like a big problem to me.
inline-block
is often promoted as a modern alternative to using float
everywhere. But neither is genuinely suitable. This is why CSS3 will standardize new layout modes: "flexbox" and "grid", to support modern responsive designs with genuine, clean markup. No dummy markup (or dummy generated content). No hacking around whitespace-dependence.
The only elements I can think of that have an in-line appearance, but allow for a width
and height
to be set, are:
img
,input
,textarea
select
, andbutton
The only element here, though, that can take HTML content is the button
element; which is not an ideal use of the button
since it's intended to be an element with which the user might/should interact; rather than simply a container element.
While you may have multiple uses for such an element, there's no convincing reason, given the ease with which the display
property might be changed, that the W3C, or any other authority, should explicitly define one; especially given that the only difference between inline
and inline-block
is the ability to assign dimensions and margin
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With