newcoder1010 Posted December 24, 2017 Share Posted December 24, 2017 Hello, HTML: <section class ="patent"> <div class ="child"> </div> </section> CSS: .parent{text-align:center;} It centers everything inside child class. .child{margin:0 auto;} It does nothing. How can I place div class child in the center of the page? I will have other div classes inside child classes. I would like to center child div instead of centering elements inside the child class. Please advise. Link to comment Share on other sites More sharing options...
Ingolme Posted December 24, 2017 Share Posted December 24, 2017 The child div needs a width. The concept of centering doesn't make sense when the element is as wide as the screen. Link to comment Share on other sites More sharing options...
dsonesuk Posted December 24, 2017 Share Posted December 24, 2017 If you want to centre .child using text-align, it must be a inline-block which makes it act like text, then you need to counteract the text align: center; by resetting it .parent {text-align: center;} .parent > .child{display: inline-block; text-align: initial;} Note your section class has 'patent' NOT 'parent' Link to comment Share on other sites More sharing options...
newcoder1010 Posted December 25, 2017 Author Share Posted December 25, 2017 Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now