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

PHP

Zachary Vacek
Zachary Vacek
3,265 Points

flexbox styles no longer applied to HTML markup applied inside PHP block.

I've run into something curious. I am working on a page similar to one we created in the build a basic website with PHP course. I am using flexbox to layout the content, which is a catalog of book covers. When my file was only HTML and CSS, flexbox worked perfectly. When I converted the file to PHP and used a data.php file and a foreach loop within the index.php file, flexbox is no longer working to layout the content. Can anyone pinpoint why?

Here is the php:

  <div class="content">
   <div class="suggestions">
    <div class="wrapper">
      <h2>May I Make a Suggestion?</h2>
      <ul class="items">
        <div class="list-section">
          <?php
            foreach ($catalog as $item) {
              echo "<li><a href='#'><img src='"
                      . $item["img"] . "' alt ='"
                      . $item["title"] . "' /></a></li>"
                      . "<p>" . $item["title"] . "</p>"
                      . "<p>" . $item["authors"] . "</p>";
            }
          ?>
        </div>
      </ul>
    </div>
   </div>
 </div>


</body>

</html>

And here is the css:

.content .items {
  padding: 0;
  list-style-type: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}

.content .list-section {
  padding: 0 10px;
}

.content li img {
  width: 90%;
}

1 Answer

Duane Simer
Duane Simer
2,140 Points

I duplicated this using my own images, and it seems to be working fine.

What specifically is it not doing? May I see the rest of the page ( the stuff above the opening div)?

These things might help me figure out what your issue is.

Zachary Vacek
Zachary Vacek
3,265 Points

Hi Duane,

I found the problem. I think I wasn't specific enough in my description of the problem. I wasn't having a problem with getting the images to appear. They just weren't being laid out on the page properly. They were all laid out in a column instead of in rows, but after I adjusted the size and margins a bit, I was able to create the rows of images. I guess it was more of a CSS problem than PHP.

Thanks for your help!