Question about section and container divs
Hello, I have a question. i have seen some people put container div inside of a section, and add css like this:
section{
padding-block: 5rem 10rem;
}
.container{
max-width: 1200px;
margin-inline: auto;
padding-inline: 2rem;
}
—
I know that we can add background to section this way and let it take width of full window, but if theres no background is it possible to put it all in a section tag ? And does it matter if theres div container or no? Thank you
—
section{
padding-block: 5rem 10rem;
max-width: 1200px;
margin-inline: auto;
padding-inline: 2rem;
}
4 Replies
The container is basically a utility class to set the max width and center it. If you don't need a full width bg, just use the container to constrain and nix the section.
What if theres no background at all? Do I still need container or can all code be in section
divs are only ever a layout tool. If you don't need it for the layout, you don't need it at all
You probably want the container class to set a max-width but you can put that class on your section , it doesn't have to be a div and will apply the styles of container to your section