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
Sunil Padmanabhan
1,344 PointsCSS Floats
I am working on a test project after completing the CSS Basics Course
I have three 3 Div blocks that I wish to place adjacent to each other I applied float to position 2 of the Div blocks on the left and right. How do I place a Div block in the center?
2 Answers
Jonathan Grieve
Treehouse Moderator 91,254 PointsI think to control the placement of a particular div you'd be better off using Grids or flexbox.
Floats affect the normal flow of elements but aren't really specific. The best thing you could do with floats is simply float the elements, then simply switch the content in your HTML.
Mind you, with 3 elements if you play around you can affect the position of eleents in a row
div#1 {
display: block;
width: 200px;
height: 200px;
float: left;
}
div#2 {
display: block;
width: 200px;
height: 200px;
float: right;
}
div#3 {
display: block;
width: 200px;
height: 200px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Floats</title>
</head>
<body>
<div id = "one">1</div>
<div id = "two">2</div>
<div id = "three">3</div>
</body>
</html>
Sunil Padmanabhan
1,344 PointsThanks, I have used the flexbox instead and it works perfectly