Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Ashley Elson
Front End Web Development Techdegree Student 5,972 PointsHow do I center floated list items?
Hi, I working on Unit 2 on the Front-End TechDegree and I'm having a little issue. I can't seem to center these list items that I have floated to the left. Does anyone know the answer or can help me?
https://gyazo.com/caa6e0d4b8f5bab393ea4bf2c4f1664b
I need the black boxes centered in the blue box.
1 Answer
Kieran Barker
15,028 PointsHi Ashley,
You have two main options!
If you give each inner floated element a width of 45%, for example, you can apply a margin of 2.5% on every side. This will then add up to 100%.
If you don't need to float the elements, another option would be to give the inner elements display: inline-block; and apply text-align: center; to the parent element.
I made this quick CodePen to demonstrate what I mean: https://codepen.io/kieranbarker/pen/VyBLvP
I hope this helps!
Ashley Elson
Front End Web Development Techdegree Student 5,972 PointsAshley Elson
Front End Web Development Techdegree Student 5,972 PointsThank you! I'm going to save this for the future