HTML HTML tag block layout

Even some ten years ago in RuNet, the so-called tabular layout was most often used. Due to the fact that the standards of some browsers were significantly different from each other, I had to look for a solution that would allow the Internet document to display correctly in all applications. But time passed, standards evolved, and the rather rigid and inflexible tabular table was replaced by a well-modifiable and responsive block layout. The cornerstone of this technology is the principle of using <div> elements. HTML documents for the most part began to be built on the basis of individual blocks, which, unlike table layout, can be independent of each other.

Occurrence

html div

The complexity of web pages and the development of computer technology has led to the fact that the web document was divided into two parts - the frame (HTML-code) and design (style sheets). Thanks to this, an unprecedented development of the web was achieved, the results of which we can now see on most modern sites. In addition to improving the development process, <div> HTML allowed us to define our own design rules for each individual element. This has contributed to improving the readability of the web page code and reducing the loading time of the document. Now search engines process much faster and better information available on the site.

Standards and Verification

The HTML <div> tag is used in strict accordance with W3C (World Wide Web Consortium) standards. Checking the page code is carried out by a special tool - a validator that parses (scans and searches) for all kinds of errors on the page. A valid page means that all tags have been used correctly and are fully compliant with the standards.

html div tag

The <div> tags allow you to create blocks or, as they are also called, containers. At the same time, individual elements can be embedded in each other, while creating structures of the necessary configuration and complexity. The use of the <div> tag without a class or identifier is almost never encountered. This is due to the "facelessness" of the element. If you do not assign a class to it, then in the end all the containers will have the same configuration.

In order to create a truly correct document, you must use the following structure of the <div> class = "some_name" tag. Referring to the class name, in the style tables you can determine the position, size, summing up and other parameters of an individual block in the document.

Using classes and identifiers

div in html

The HTML <div> block can be defined either by id or by class class. The difference between the first and the second is that id is used on the document page only once. That is, it is used to identify unique elements that are not repeated anywhere in the page code. A class attribute allows you to apply the same style rules to multiple elements. This approach greatly simplifies code development and maintenance. In addition, one object can have several classes at the same time. For proper recognition, they are simply separated by spaces.

Naturally, the block structure of the document does not at all imply the use of only <div> tags. There will always be other elements in the structure of any web page. In addition, the block <div> element itself can have a completely different display. This is done using the display property. An element can have a line or even a tabular display, which can significantly increase the flexibility of using the block and create a site of any configuration.

<div> tag. HTML properties

div class

As mentioned above, this tag does not change the design of the page fragment, but is used to create a semantic structure with subsequent design through style sheets. The use of a closing tag for this element is required.

Despite the fact that many modern browsers will be able to recognize such an error, in some cases an unclosed tag can cause the structure of the document to “fall apart” and display it incorrectly.

Since this element is block, the content contained in it will begin on a new line. To change this behavior, you need to change the display parameters of the block with the display property. In addition to grouping nested elements, the <div> tag allows you to format the location of content inside it. To do this, use the align attribute, thanks to which you can place text or an image on the left edge, on the right edge, or in the center of the parent element.

Block positioning

What is a div in html

Using the position attribute allows you to change the positioning method of the selected element. So, there are three types of positioning:

  • Static - used by default. In this case, the element is positioned according to the position in the HTML code.
  • Relative In this case, the location of the object is calculated in the same way as in the case of static positioning, but this property allows you to change the position for child elements.
  • Absolute Its position is calculated relative to an element with relative positioning.

Other attributes

To change the position relative to the origin, the top and left attributes are used. Values ​​can be either positive or negative. The width and height of the block element are set by the width and height attributes, respectively. If they were not specified in the style sheets, then the block will occupy the entire width of the parent element. If the content of the block does not fit the entire width of the "parent", then the behavior of the element is determined by the overflow attribute.

We hope this article helped to understand the question of what <div> is in HTML.

Source: https://habr.com/ru/post/C3098/


All Articles