Skip to content

Responsive Container Class

Simon Padbury edited this page Dec 25, 2018 · 1 revision

Bootstrap has a .container class that snaps to set max-widths at breakpoints:

// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) { max-width: 540px; }

// Medium devices (tablets, 768px and up)
@media (min-width: 768px) { max-width: 720px; }

// Large devices (desktops, 992px and up)
@media (min-width: 992px) { max-width: 960px; }

// Extra large devices (large desktops, 1200px and up)
@media (min-width: 1200px) { max-width: 1140px; }

The Bootstrap .container-fluid class doesn’t have these step changes, and it maxes out at the width of the viewport.

What if you want the best of both worlds — a fluid layout that maxes out the same as .container but without the step changes? Meet my .container-responsive class. Add this to your CSS:

.container-responsive {
	width: 100%;
	max-width: 1140px;
	padding-right: 15px;
	padding-left: 15px;
	margin-right: auto;
	margin-left: auto;
}
.navbar > .container-responsive {
	display: -webkit-box;
	display: -ms-flexbox;
	display: flex;
	-ms-flex-wrap: wrap;
	flex-wrap: wrap;
	-webkit-box-align: center;
	-ms-flex-align: center;
	align-items: center;
	-webkit-box-pack: justify;
	-ms-flex-pack: justify;
	justify-content: space-between;
}