CSS Element Types

Ultimately, stylesheets are intended to play no more than a silent and hidden role. They define a protocol for the layout and display of material by a web browser. The actual application of the protocol is done by the web browser after examining the nature of the (X)HTML element to which the CSS rule is being applied. In order to make good use of the power of cascading style sheets it is essential to recognize that there are two categories of element:

Strictly speaking it makes no sense to adjust the margin or the padding of an inline element. Nevertheless these properties exist and can be legitimately assigned and changed. Why? The reason is that the type of an element, block or inline, is not immutable. It is possible to change the manner in which an element displays by changing its display property to none, block, inline, inline-block etc. Changing the display property can be used to good effect to create pure CSS buttons as described here. It should be noted though that setting position:absolute;, position:fixed; or float:left|right in the CSS rule results in inline elements being converted into block elements. In such circumstances there are legitimate reasons for using the margin and padding properties. However, indiscriminate use of these properties for true inline elements can result in unpredictable and confusing displays.

Can inline elements act as containers for other elements? You would be breaking no rules by placing, say, a list-item inside an anchor. However, the result would be a website that most users would find difficult to use. Needless to say there are legitimate ways of nesting elements inline - for example, anchors inside list-item elements.

Jump To...

Colophon