Hello, I was working through step 9 of the flexbox course, and found that I have a different result when I run the code as a file on my computer or codepen.io then in the freecodecamp emulator.
Here is the html code in free code camp:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Photo Gallery</title>
<link rel="stylesheet" href="./styles.css">
</head>
<body>
<header class="header">
<h1>css flexbox photo gallery</h1>
</header>
<div class="gallery">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/1.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/2.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/3.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/4.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/5.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/6.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/7.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/8.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/9.jpg">
</div>
</body>
</html>
With CSS:
* {
box-sizing: border-box;
}
.gallery {
border: 5px solid red;
width: 50%;
}
img {
width: 100%;
border: 5px solid blue;
padding: 5px;
}
I saved this code to my computer, and opened it in my browser (Firefox 131.0.2 on Linux Mint).
In the image below, the a) screenshot shows the result from FCC, no white between the blue and red borders. The b) screenshot shows the result from my browser, where you can see there is a space between the red and blue borders. The is also a space between the blue borders of adjacent images.
Why does it look different?
SOLVED!
In the saved code, I changed the display
property of img
to block.
img {
width: 100%;
border: 5px solid blue;
padding: 5px;
display: block;
}
This fixed the rendering in the browser to remove the extra space.
I think free code camp must set img{display:block}
by default, but it isn’t in the CSS file so this should probably be fixed.
I have opened an issue on github:
opened 02:13AM - 13 Oct 24 UTC
scope: curriculum
status: waiting triage
### Describe the Issue
In step 9 of the responsive web design: flexbox course, … running the code in another browser will produce a different result to running the code in the FCC emulator. I outline the issue in [this forum post](https://forum.freecodecamp.org/t/different-rendered-results-outside-of-freecodecamp-flexbox-photo-gallery-step-9/716021).
I have included the html and css code below. This is the solution to problem 9, and the rendered website in FCC can be seen in the screenshot a). When I save the code to my computer and run it in my browser, the rendered result looks like screenshot b). Notice the extra white space around the images.
### Affected Page
https://www.freecodecamp.org/learn/2022/responsive-web-design/learn-css-flexbox-by-building-a-photo-gallery/step-9
### Your code
styles.css
```
* {
box-sizing: border-box;
}
.gallery {
border: 5px solid red;
width: 50%;
}
img {
width: 100%;
border: 5px solid blue;
padding: 5px;
}
```
x.html
```
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Photo Gallery</title>
<link rel="stylesheet" href="./styles.css">
</head>
<body>
<header class="header">
<h1>css flexbox photo gallery</h1>
</header>
<div class="gallery">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/1.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/2.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/3.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/4.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/5.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/6.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/7.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/8.jpg">
<img src="https://cdn.freecodecamp.org/curriculum/css-photo-gallery/9.jpg">
</div>
</body>
</html>
```
### Expected behavior
I expected the rendered output to be the same.
### Screenshots

### System
- Device: [Laptop]
- OS: [Linux Mint 21]
- Browser: [Firefox]
- Version: [131.0.2]
### Additional context
Adding `img {display:block}` in the css fixes the issue. I would guess that somewhere in the FCC rendering, the images are set to block display. This isn't immediately made clear to the user.
system
Closed
April 13, 2025, 2:16pm
4
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.