Intro
Hello world! Welcome to another blog post for Anthonyâs Techie Thoughts! If youâre new here, my name is Anthony and Iâm studying programming to make a career change from mathematics teacher to frontend web developer. In my blog posts I reflect on my journey and share things Iâm learning along the way. You can find me on GitHub, LinkedIn, Hashnode, DEV.to, and CodeNewbie.
This week I continued working my way through the curriculum on Scrimba.com, Sololearn.com, and Kevin Powellâs âConquering Responsive Layoutsâ course. In this blog post Iâll share the 3 lines of CSS I learned to keep page elements centered and responsive.
Weekly Reflection
My progress was slow and steady this week due to some extra responsibilities at work. I would have liked to had made more progress, especially with the ideas Iâm learning in Kevinâs course, but sometimes life gets in the way and you just gotta roll with it. Throughout this week one idea from Kevin Powellâs course has stuck with me: using width
, max-width
, and margin
to center elements on a page.
His approach is simple and uses a minimal amount of code. This is something I (as a novice) can appreciate because it lessens the burden of entry to building responsive websites. For example, the following is the minimal amount of CSS code needed to center a container
on a page, ensure that it fills 80% of the body width, and sets a limit on how wide it will stretch (this is particularly helpful for really wide screens, the text when spread all the way across):
.container {
width: 80%;
max-width: 1100px;
margin: 0 auto;
}
The max-width
property will change depending on what is in the container and the design of the page â as could the width: 80%
if you didnât want it to fill 80% of the pageâs width â but these are the core properties needed to center the .container
on the page. As an example, this CodePen features my solution to a challenge from Kevin Powellâs course that makes use of this idea in practice. The goal is to create a responsive webpage that uses flexbox to create columns and rows of content while implementing these 3 lines of CSS to keep the elements centered and responsive.
Previously, I had been using any and all properties to get things to center on the page (e.g., height, width, display, etc.) â most of it unnecessary. With these three lines of code things are centered and responsive. Granted, this isnât the end of the line but the start. There may be more styling properties required based on the design specifications of the page, but this comes later and in other places.
Iâve only completed up to Day 9 of his 21-day course, but ideas such as this one have already triggered thoughts like, âoh, that wouldâve been helpful for project X, instead of using gliff, glaff, and gluff to do the same thingâ. But this is the nature of learning. You crawl (and stumble) before you learn to walk and run. After Iâm done with his course, Iâd like to go back to previous Frontend Mentor projects and apply what Iâve learned (and, of course, carry these ideas into new projects).
Projects from the Week
- Scrimba Project
- Basic Blackjack App
Thanks for reading
Thanks so much for reading this post. I hope you found it useful and inspiring. Whatâs a big idea you learned this week thatâs stuck with you? Feel free to share your thoughts in the comments below. Hearing your thoughts makes this more of a conversation and helps everyone learn.
Top comments (1)
If you're still looking for effective ways to get your website optimized properly and deliver appropriate marketing results, you may be eager to consider innovative web design and marketing services for the maximum value and effectiveness you may expect. By getting familiar with smart solutions at loungelizard.com you'll be confident you're making the right choice.