Codelab: Centering in CSS
Stay organized with collections
Save and categorize content based on your preferences.
This codelab sets you up to share and showcase your favorite way of centering in
CSS.
Check out my blog post Centering in CSS to learn about 5 of
my favorite ways to center in CSS. Or watch this video!
Setup
- Click Remix to Edit to make the project editable.
- Open
app/index.html
- At
line 23
, replace /* your centering CSS here /*
with your CSS
- (optional) Name your centering technique and replace the text in the
<h1>
Styles
- Create a new file in the
app/css/
folder
- Create a selector to hold your centering solution, like
.turbo-center
or
[floaty-mcfloat]
- Within that new selector, write your centering technique (feel free to look
at the other's in
app/css/
as examples)
- (optional) write some "support styles" so we can see which children need
styles to support the centering
- Open
app/css/index.css
and import your new file at the bottom
Tie it all up
- Open
app/index.html
again
- Find the
<article>
and give it your custom selector you made in step #2 of
the previous section.
- Tweet me your Glitch and I'll feature it on
the blog post!
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-12-16 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]