

What you would notice is that it successfully moved to the center. Now try adding display: block text-align: center on that span element. You would notice the span element doesn't move to the center, this is because of the type of element. Now try this CSS declaration on a div element and then a span element. One of the common ways to align items to the center is text-align: center. There are different ways to center align texts and elements in CSS, but not all of it will work for all elements, for example What are the already declared styles of these elements (parent and child)? That is if there are any. Which element is to be styled when center aligning a child element, the parent element or the child element itself? What type of element are you center aligning? Is it block or inline?

You are not going to find what I found that way. Now don't be quick to go to YouTube to search "cheat in aligning items to the center". Beginners and sometimes professionals often find themselves googling this topic when they get stuck while trying to center align texts or elements in CSS.įrom my experience, center aligning has never been a problem to me since I saw a cheat in a YouTube video.

Center aligning items has being a much-discussed topic in CSS.
