Why nest container divs in section/nav/article elements?

This has likely been covered before, but it feels like a really generic thing to find with search. I'm making my way through "Build a responsive website with HTML & CSS" playlist and I saw Kevin nesting a container div inside other elements like <nav> <div class="container"> ... or <section> <div class="container"> ... Why not style the section or nav elements directly?
23 Replies
b1mind
b1mindā€¢8mo ago
Big ol #depends Without any other context I would say there is no good reason and they should just be the containers
Roman
RomanOPā€¢8mo ago
fair point, this is the specific part of the video https://youtu.be/3K6zr1CdZy8?si=Xe8odfUzuBQXbZt7&t=903
Kevin Powell
YouTube
Build a responsive website with HTML & CSS | Part two: Writing the ...
It's time to write the HTML for our project! If you missed part 1, you can find it here: https://www.youtube.com/watch?v=3K6zr1CdZy8 šŸ”— Links āœ… The code from Part 1: https://github.com/kevin-powell/fem-manage-landing-page-part-1 āœ… More on Semantic HTML: https://youtu.be/NexL5_Vdoq8 #css -- Come hang out with other dev's in my Discor...
Roman
RomanOPā€¢8mo ago
GitHub
fem-manage-landing-page-part-2/index.html at master Ā· kevin-powell/...
Contribute to kevin-powell/fem-manage-landing-page-part-2 development by creating an account on GitHub.
b1mind
b1mindā€¢8mo ago
Well that shows he did put a class on the nav Few things he could have done better in that though probably each section could get the container class like you pointed out. Also the* divs wrapping the headings w/paragraphs could be <header> elements Just remember when learning that most things can be improved on and teachers are just people too, not everything they are doing in that moment is going to be what you want maybe.
vince
vinceā€¢8mo ago
There are also times you want your inner container to be styled differently than your parent container. Eg your container class has a max-width on it and you want your parent container (section / nav) be be full width
b1mind
b1mindā€¢8mo ago
yea good point always #depends which he does do some styles on other <section>s it looks like. So there is a reason. yea so looking a bit closer at the repo code, Vince pretty much nailed why Kevin did it container is to keep the max-width and things justified the same, while the sections can fill full width and get different bg colors or what have you i.e.
<section class="cta | bg-primary-400 text-neutral-100">
<div class="container">
<section class="cta | bg-primary-400 text-neutral-100">
<div class="container">
b1mind
b1mindā€¢8mo ago
Kevin Powell
YouTube
A new approach to container and wrapper classes
The wrapper or container is probably the most common design pattern around, but after coming across an article by Stephanie Eckles looking at how we can use a grid to emulate a container, and have simple breakouts ā€” https://smolcss.dev/#smol-breakout-grid ā€” I had an idea of how we could do this to completely drop the idea of containers, and then...
b1mind
b1mindā€¢8mo ago
This is my fav way do do it ā¤ļø #gridLifeIsNice Which would eliminate the extra wrappers. (in most cases anyway) #depends lol
vince
vinceā€¢8mo ago
i keep seeing this vid but i've been lazy... ill have to check it out šŸ‘€
b1mind
b1mindā€¢8mo ago
Yea it was already my new favorite way to wrapper, glad Kevin made the video. Showed him mine and the og article. ā¤ļø Grid is life
Cake
Cakeā€¢8mo ago
that's called having good semantics, has nothing to do with styles https://developer.mozilla.org/en-US/docs/Glossary/Semantics
No description
b1mind
b1mindā€¢8mo ago
They are not questioning the semantics, but if the extra divs where necessary.
Cake
Cakeā€¢8mo ago
they necessary for good semantcis they are not extra divs they said <nav> and <section>
b1mind
b1mindā€¢8mo ago
I think you are missing the point
Cake
Cakeā€¢8mo ago
in their question which they thought it's for styling purposes
b1mind
b1mindā€¢8mo ago
Yes and why can't they be the ones being styled
Cake
Cakeā€¢8mo ago
which is not. they didn't ask about
<div>
<div>
<div>
<div>
b1mind
b1mindā€¢8mo ago
I'm not going to go circles with you šŸ˜‚
Cake
Cakeā€¢8mo ago
you guys lack knowledge based on my last interactions with u
b1mind
b1mindā€¢8mo ago
You don't know me, so I'd avoid insulting me
Cake
Cakeā€¢8mo ago
i do we're literally seeing the same question nvm, you're right missed the last part of the question
b1mind
b1mindā€¢8mo ago
Happens I do it too, also if you knew me you would know I very much love semantics and accessibility... It's something I talk about A LOT Hence why I pointed out <header> being a better r wrapper in the sections around the heading
Roman
RomanOPā€¢8mo ago
I remember watching that a few months ago, re-watched it on your recommendation, it made a lot more sense second time around How did you imagine this interaction going? There's basically no way to interpret that other than an insult. Why insult random people on the internet instead of taking a few more questions to clarify your understanding? If your goal was answering my question or just adding new perspective to the discussion, "you lack understanding" has basically 0 chance of achieving that if the goal was to be an internet badass, no one will be impressed unless you're behind seven proxies
Want results from more Discord servers?
Add your server