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

CSS

Matthew Thompson
Matthew Thompson
3,554 Points

Can I use multiple flexboxes in my index.html? If so do I restart .item-1 on the second or would I continue from prior?

<div class="container">
  <div class="item-1 item">Item 1</div>
  <div class="item-2 item">Item 2</div>
  <div class="item-3 item">Item 3</div>
  <div class="item-4 item">Item 4</div>
  <div class="item-5 item">Item 5</div>
  <div class="item-6 item">Item 6</div>
</div>
<div class="container-1">
  <div class="item-1 item">Item A</div>
   <!--    OR    -->
  <div class="item-7 item">Item A</div>
</div>

2 Answers

Rich Donnellan
MOD
Rich Donnellan
Treehouse Moderator 27,671 Points

Fixed the formatting for you.

It really depends on the context of the situation. Do you really need to differentiate between each list item? Would .item suffice? Is there CSS to go along with this? If so, update your question to include.

I'd also avoid using item-# for a class name, as it's not very semantic (meaningful).

Hope this sheds some light.

Matthew Thompson
Matthew Thompson
3,554 Points

I thought that item-# for a class name was necessary for the flexbox to work. I can use any class name that I want for the items inside of a flexbox? If that is the case then I believe it wouldn't be a problem to use multiple flex containers on a page. Thank you for such a fast response.

An example of the proper format for using different naming would be appreciated. Would it be something like:

<div class="main-gallery">
  <div class="image-1 gallery">Item 1</div>
  <div class="image-2 gallery">Item 2</div>
</div>

Team Treehouse is the best!

Rich Donnellan
MOD
Rich Donnellan
Treehouse Moderator 27,671 Points

I'm not sure where you heard that, but it's incorrect. Class names can be whatever you want. Are you going through a specific course here at Treehouse?

Basically, a flex container requires a display: flex; to become flexible and all direct children become flex items. Indeed, you are allowed multiple flex containers. Check out this CSS-Tricks guide for some great information.

Without knowing what you are building, it's hard to recommend a structure/naming convention for classes. Here's my stab anyway:

<div class="main-gallery">
  <img class="img img--gallery" src="path-goes-here.jpg" alt="Image description for screen readers.">
  <img class="img img--gallery" src="path-goes-here.jpg" alt="Image description for screen readers.">
  <img class="img img--gallery" src="path-goes-here.jpg" alt="Image description for screen readers.">
</div>
// Random properties/values being used here for example purposes only
.main-gallery {
  display: flex;
  flex-wrap: wrap;
  width: 50%;
}
.img {
  max-width: 100%;
  height: auto;
}
.img--gallery {
  background-color: #fff;
  border: 1px solid #eee
  padding: 0.5em