The Center Design Pattern
The center pattern is used to cap out the inline growth while centering the content inside its parent.
Get the project source code below, and follow along with the lesson material.
Download Project Source CodeTo set up the project on your local machine, please follow the directions provided in the README.md
file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.
Lesson Transcript
[00:00 - 00:03] Okay, welcome back. In this lesson, we're gonna talk about the centered design pattern.
[00:04 - 00:27] Now the centered design pattern is when you have an element that needs to stop growing horizontally or in the inline direction and you want to center its content in that inline direction. So here we have an example of content that stopped growing at a certain width and centered inside the parent container.
[00:28 - 00:59] This one maybe is a little less obvious 'cause the screenshot cut out this line here on the slides but we have this content stop growing even though the parent container is continuing to grow and the content is centered inside of this parent container. So let's go through this example application again and I want you to identify examples of centered content.
[01:00 - 01:24] Okay, so this may have been one that a lot of people miss but this entire application is actually centered. It's in a center content 'cause you see the parent container which in this case is the body of the page has continued to grow, to take the entire width but the content itself stopped growing at a particular size and centered itself.
[01:25 - 01:33] So this whole thing is in a centered component. We have this area, this is centered.
[01:34 - 01:39] So this box stop growing and is centered. We have this box is centered.
[01:40 - 01:59] This box is in the centered component but it's still taking up the entire width 'cause it hasn't grown yet to the point where it would center. So even though it is still taking up the entire width that doesn't mean it hasn't, isn't being used as a center component.
[02:00 - 02:19] But yeah, we have this item and then this might be considered centered but the reason it's not is because it's already an inline component and we're just justifying the content center. So this is actually clustering in the center and that's why it is not a center component.
[02:20 - 02:25] So these are examples of the center pattern in use.
This lesson preview is part of the Mastering CSS Layout course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.
Get unlimited access to Mastering CSS Layout, plus 70+ \newline books, guides and courses with the \newline Pro subscription.
![Thumbnail for the \newline course Mastering CSS Layout](/_next/image?url=https%3A%2F%2Fs3.amazonaws.com%2Fassets.fullstack.io%2Fn%2F20240307133806039_TravisWaith-Mair_MasteringCSSLayout_1450.67x816_CoverImage%2520%25282%2529.png&w=3840&q=75)