3

I'm asking this for a class assignment I'm working on, and somehow I've broken CSS so bad that even my teacher is stumped.

body {
  font-family: Georgia, serif;
  background: url("graphics/Background.png");
  margin: 5%;
}

h1 {
  text-align: center;
  padding: 0px 0px 20px 0px;
}

.panel {
  border: 3px solid black;
  width: 500px;
  height: 500px;
  margin: 20px;
}

#container {
  display: flex;
  align-content: space-between;
  justify-content: center;
  background-color: red;
  flex-direction: column;
}
<h1>Sunday Funnies</h1>
<div id="container">
  <img class="panel" src="Graphics/placeholder.png">
  <img class="panel" src="Graphics/placeholder.png">
</div>
</div>

```

This is what I have after my professor did some tinkering to try and figure out what was going on.

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
H. Davis
  • 55
  • 1
  • 5

2 Answers2

2

align-content targets flex lines, not flex items.

You need to use align-items.

Plus, align-content has no effect in a single-line flex container (i.e., flex-wrap: nowrap).

h1 {
  text-align: center;
}

#container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: red;
}

.panel {
  border: 3px solid black;
  width: 100px;
  height: 100px;
  margin: 20px;
}
<h1>Sunday Funnies</h1>
<div id="container">
  <img class="panel" src="http://i.imgur.com/60PVLis.png">
  <img class="panel" src="http://i.imgur.com/60PVLis.png">
</div>

Here's a detailed explanation of cross-axis alignment:


From the flexbox spec:

§ 8.4. Packing Flex Lines: the align-content property

The align-content property aligns a flex container’s lines within the flex container when there is extra space in the cross-axis, similar to how justify-content aligns individual items within the main-axis. Note, this property has no effect on a single-line flex container.

(emphasis mine)

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
0
  1. You want align-items, not align-content
  2. justify-content refers to the main axis, whereas align-items refers to the cross-axis. This means that you likely want align-items: center if your intention is to center the items horizontally.

body {
  font-family: Georgia, serif;
  background: url("graphics/Background.png");
  margin: 5%;
}

h1 {
  text-align: center;
  padding: 0px 0px 20px 0px;
}

.panel {
  border: 3px solid black;
  width: 500px;
  height: 500px;
  margin: 20px;
}

#container {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: red;
  flex-direction: column;
}
<h1>Sunday Funnies</h1>
<div id="container">
  <img class="panel" src="Graphics/placeholder.png">
  <img class="panel" src="Graphics/placeholder.png">
</div>
Tyler Roper
  • 21,445
  • 6
  • 33
  • 56