{"id":2026,"date":"2025-04-14T01:35:40","date_gmt":"2025-04-14T01:35:40","guid":{"rendered":"https:\/\/appliedartand.design\/lj\/?p=2026"},"modified":"2025-04-14T01:35:40","modified_gmt":"2025-04-14T01:35:40","slug":"for-centering-which-works-when","status":"publish","type":"post","link":"https:\/\/appliedartand.design\/lj\/2025\/04\/14\/for-centering-which-works-when\/","title":{"rendered":"For centering, which works when?"},"content":{"rendered":"\n<p>Trying to center stuff horizontally shouldn\u2019t be so confusing! I find myself cycling through all the possible CSS rules until I find one that works.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>I looked around online for a more efficient method and found a helpful discussion on <a href=\"http:\/\/stackoverflow.com\">StackOverflow.com<\/a> that contained several descriptions, illustrations, and resources. I summarized what I learned in the table below.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>S<strong>tuff to Center<\/strong><\/td><td><strong>CSS Rule<\/strong><\/td><td><strong>Affect<\/strong><\/td><\/tr><tr><td>Block element<\/td><td>margin: auto;<\/td><td>Adjusts left and right margins to center the element.<\/td><\/tr><tr><td>Text inside element<\/td><td>text-align: center;<\/td><td>Sets horizontal alignment of the inline-level content.<\/td><\/tr><tr><td>Image<\/td><td>display: block;<br>margin-left: auto;<br>margin-right: auto;<\/td><td>Turns image into a block element so its margins can be adjusted.<\/td><\/tr><tr><td>Content within element<\/td><td>justify-content: center;<\/td><td>Controls alignment of grid <strong>columns <\/strong>by adjusting <strong>padding <\/strong>within the element.<br>Does not control items.<\/td><\/tr><tr><td>Element within parent<\/td><td>justify-items: center;<\/td><td>Controls alignment of grid <strong>items <\/strong>by adjusting <strong>margins <\/strong>within the parent.<\/td><\/tr><tr><td>Items inside box<\/td><td>justify-self: center;<\/td><td>Overrides justify-items on individual child items. If left on default, inherits values of justify-items.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>W3School&#8217;s <a href=\"https:\/\/www.w3.org\/TR\/css-align-3\/#overview\">CSS Box Alignments Module Level 3<\/a> also contained a helpful graphic that I pasted below. The graphic illustrates how justify-content adjusts padding, justify-items adjusts margins, and justify-self overrides justify-items on individual child elements.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXcZ97nwlTOcwEelImHjpinnn6n1-b_3a4eGOAgLJ3Nn_EJuJg0FvaVmlPieTxHhq80URKpqVyZwVrWe7wvW5gxhq39iQVNZEjhDD8NZYNGKKhAMwBtPzRXYU5UcqqKNv0zWm2YGAg?key=YVOLaUIAnsMMaXp8tDLIdH3H\" alt=\"\" \/><\/figure>\n\n\n\n<p>I think I now have a better grasp of which CSS rule to use based on the selector. I look forward to applying what I learned to my next project!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Trying to center stuff horizontally shouldn\u2019t be so confusing! I find myself cycling through all the possible CSS rules until I find one that works.<\/p>\n","protected":false},"author":94,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[240],"tags":[32,4,23,3,18],"class_list":["post-2026","post","type-post","status-publish","format-standard","hentry","category-aad-086-sp25","tag-coding","tag-css","tag-css-layout","tag-html","tag-web-design"],"_links":{"self":[{"href":"https:\/\/appliedartand.design\/lj\/wp-json\/wp\/v2\/posts\/2026","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/appliedartand.design\/lj\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/appliedartand.design\/lj\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/appliedartand.design\/lj\/wp-json\/wp\/v2\/users\/94"}],"replies":[{"embeddable":true,"href":"https:\/\/appliedartand.design\/lj\/wp-json\/wp\/v2\/comments?post=2026"}],"version-history":[{"count":2,"href":"https:\/\/appliedartand.design\/lj\/wp-json\/wp\/v2\/posts\/2026\/revisions"}],"predecessor-version":[{"id":2028,"href":"https:\/\/appliedartand.design\/lj\/wp-json\/wp\/v2\/posts\/2026\/revisions\/2028"}],"wp:attachment":[{"href":"https:\/\/appliedartand.design\/lj\/wp-json\/wp\/v2\/media?parent=2026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appliedartand.design\/lj\/wp-json\/wp\/v2\/categories?post=2026"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appliedartand.design\/lj\/wp-json\/wp\/v2\/tags?post=2026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}