r/learnwebdev • u/UnderPressureICrackn • Jan 13 '20
Question about "Div-itis"
So, I am learning HTML, CSS, and JavaScript first. I went through the HTML and CSS portions, and am currently on JS. However, I was curious about this "div-itis" I keep hearing about. I get what it is...and I get how to avoid it (kinda) What I am curious about it when to use it properly. In what situations would it be a good idea to use the <div>?
2
Upvotes
View all comments
Show parent comment
1
u/[deleted] Jan 15 '20 edited Jan 15 '20
I'm not really following this. Using divs and CSS are not mutually exclusive. CSS is for styling, but you need markup to style in the first place.
When building complex layouts and components, it's often necessary to group or break up portions of content with a generic container element to achieve a desired result. When that needs to be done to flow content in a way that isn't better described with a semantic element (
<header>,<article>,<section>, etc.) then a div is the way to go, because it is the generic container element and comes with no inherent styling (aside fromdisplay: block).Divs are a ubiquitous part of HTML and it would be counterproductive to try and avoid using them altogether. Div-itis comes from 1) Using too many nested divs to create a result that could be achieved with fewer elements and more effective CSS, and 2) using divs in place of more appropriate elements. For example, don't create what is effectively a list with divs; use
<ol>or<ul>instead.