Блочные и строчные элементы. Блочные и встроенные элементы

HTML (Hypertext Markup Language ) elements historically were categorized as either "block-level" elements or "inline" elements. Inline elements are those which only occupy the space bounded by the tags defining the element, instead of breaking the flow of the content. In this article, we"ll examine HTML inline elements and how they differ from block-level elements .

An inline element does not start on a new line and only takes up as much width as necessary.

Inline vs. block-level elements: a demonstration

This is most easily demonstrated with a simple example. First, some simple CSS that we"ll be using:

Highlight { background-color:#ee3; }

Inline

Let"s look at the following example which demonstrates an inline element:

The following span is an inline element; its background has been colored to display both the beginning and end of the inline element"s influence.
The following paragraph is a

block-level element;

its background has been colored to display both the beginning and end of the block-level element"s influence.

The CSS (not displayed in standard reading mode) is also used:

Body { margin: 0; padding: 4px; border: 1px solid #333; } .highlight { background-color:#ee3; }

Rendered using the same CSS as before, we get:

See the difference? The

Element totally changes the layout of the text, splitting it into three segments: the text before the

Then the

"s text, and finally the text following the

Changing element levels

You can change the visual presentation of an element using the CSS display property. For example, by changing the value of display from "inline" to "block" , you can tell the browser to render the inline element in a block box rather than an inline box, and vice versa. However, doing this will not change the category and the content model of the element. For example, even if the display of the span element is changed to "block" , it still would not allow to nest a div element inside it.

Conceptual differences

In brief, here are the basic conceptual differences between inline and block-level elements:

Content model Generally, inline elements may contain only data and other inline elements. You can"t put block elements inside inline elements. Formatting By default, inline elements do not force a new line to begin in the document flow. Block elements, on the other hand, typically cause a line break to occur (although, as usual, this can be changed using CSS).

List of "inline" elements

The following elements are inline by default (although block and inline elements are no longer defined in HTML 5, use

Элементы HTML по способу отображения на веб-странице делятся на строчные и блочные элементы.

Строчные элементы (inline)

Строчные элементы предназначены для выполнения некоторых действий над текстом, например: перенос строки, выделения фрагмента текста курсивом, логического выделения некоторого текста и применения к нему стилей с помощью CSS и т.д. В зависимости от назначения строчного элемента фрагмент текста помещают между открывающим и закрывающим тегом или применяют тег в любом месте текста, например для переноса строки.

Например:
Можно использовать строчный элемент чтобы выделить текст, привлекающий внимание посетителей сайта с помощью жирного начертания.

Строчный элемент имеет ширину, которая равна ширине его содержимого. Строчные элементы не могут содержать внутри себя блочные элементы.

Примеры строчных элементов: , ,