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
Antonis Martalis
1,506 PointsAligning Images
Hello everyone and thank you for your time. My question is : If i want to make 3 images 1 next to the other should i make 3 divs and place them inside a forth one or should i make a list does it matter? and if yes why? differences??
2 Answers
Shawn Jones
15,579 PointsI feel in this case, especially with images that can be lined up as thumbnails, putting them as lists will work best because its a list of thumbnail images for one, and two selecting them makes it ten times easier because div tags are the most common used tags in html. With divs, you have to create classes and be specific, with an unordered list and list items, you might have to specify one class at most and then select deeply from there. Take this for example:
This is a group of images in an unordered list:
<ul>
<li><img src="photo1.jpg" alt="" /></li>
<li><img src="photo2.jpg" alt="" /></li>
<li><img src="photo.3.jpg" alt="" /><li>
</ul>
by using the less common ul tag which is usually only used for links as stated above, you can specify one class name to the ul and then apply specific changes to the children without having to add additional class names for further targeting.
ul with added class:
<ul class="photo_album">
<li><img src="photo1.jpg" alt="" /></li>
<li><img src="photo2.jpg" alt="" /></li>
<li><img src="photo3.jpg" alt="" /><li>
</ul>
Now I can style the parent element with positioning as well as style the individual childs as such:
/*styles for parent box that holds all the childs*/
ul.photo_album{
width: auto;
height:auto;
position:relative;
padding: 10px;
}
/* styles for children within parent element */
ul.photo_album li{
width: 200px; /* or whatever you want */
height: auto; /* or whatever you want */
float: left;
}
img{
width: 100%;
}
with one class, I was able to select any element with that parent because that tag isn't widely used across the page. Imagine if the ul tag was a div tag with a class with a bunch div's within divs. you would have had to establish at least two class names to do the same thing. It is a personal preference but I fill by using the unordered list concept, the syntax is a bit more correct because it is a list of items for one, and it's a bit easier to control and identify.
Gloria Dwomoh
13,116 PointsI suggest you use "float" because if you do divs alone or lists, which is an html property your images might not align one next to the other, but if you add the float property in your CSS it can help you do that. You can make a class in your div and add "float:right" or "float:left" to its CSS, that will float the images to the right or left. You can read more about it here.
Antonis Martalis
1,506 PointsI know float my question is what is best in coding making divs or make Lists?
Gloria Dwomoh
13,116 PointsI think that depends on your preference. I usually see that happening when someone wants to do a navigation bar...then is when you will usually see people using float to a list but when it comes to images, I haven't really seen lists being used to float them. You can do it if you want but it is not as common as div and also if in the future you will like to use something like bootstrap to turn your picture into thumbnail you won't be able to do it with "lists" because it uses divs. Overall it is up to you.