I read in the HTML5 specification that a generic tag divshould only be used as a “last resort” when a more specific element is not available. For example, tags header, footerand sectionare preferred for thematic thematic placement of content.
div
header
footer
section
But it seems that the vast majority of websites are still using divas the main element. My question is how often and in what contexts is it appropriate to use div? And what other elements should be used in their place?
I am looking for answers based on specifications, not personal opinions. Thank!
There is nothing that replaces <div>(this is the reason it is still in the specification), but HTML5 has more elements available.
<div>
In addition to <header>, <footer>and <section>:
<header>
<footer>
<section>
<nav>
<article>
<aside>
<main>
<details>
<summary>
<figure>
<dialog>
<menu>
Basically, any new HTML5 element can replace <div>.
When should you use a div? You yourself answered:
when a more specific item is unavailable
MDN has an HTML5 element list that contains all the standard HTML5 elements and indicates which elements are new with HTML5.
, div HTML5 . , div HTML4, , . , HTML5 , div .
div , , - . , HTML5, , .
section, , , , header, footer .., , , . , , , section div.
div HTML5. , . section , section .
header, section, footer , css . W3C , - div HTML5. div , . , , .
? . header, . -. . div 'header'. , .
Of great importance for divis the creation of a wrapper around all your content, like this.
<div id="wrapper"> <!--content--> </div>
Then you can reference it in css to the center:
#wrapper{margin:20px auto;}
Hope this helps!
Source: https://habr.com/ru/post/1528781/More articles:Why can't I set a Double object equal to int? - Java - javaDamage to UINavigationController on iPad + Master Detail + TabBar - iosjson_decode переформатирует десятичные знаки в JSON на основе языка - jsonAre all iOS GameCenter callbacks performed in the main thread unless otherwise noted? - multithreadingisnan is retained when you assign the FP type to a different size. - c ++Где шаблон файла SQL в Visual Studio 2010? - sqlКак установить значение в скрытом поле в соответствии с пунктом, выбранным в выпадающем списке - javascriptReturn column header of maximum value column for each row - excelInconsistent types for record fields - haskellPyplot interactive scaling - pythonAll Articles