Experminting with spacing

its driving me crazy on which way is better to space out items inside a container


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Flexbox</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div id="f">
        <div>1</div>
        <div>2</div>
        <div>3</div>
        <div>4</div>
        <div>5</div>
        <div>6</div>
        <div>7</div>
        <div>8</div>
        <div>9</div>
        <div>10</div>
        <div>11</div>
        <div>12</div>
      </div>
</body>
</html>

should i do it like

* {
  margin: 0px;
  padding: 0px;
}
#f {
  border: 1px solid blue;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  align-content: flex-start;
  width: 100%;
  min-height: 100vh;
  padding: 10px;
}
#f div {
  border: 1px solid red;
  width: 300px;
  height: 300px;
  margin: 20px;
}
#f div:nth-child(1) {
  background-color: aquamarine;
}
#f div:nth-child(10) {
  background-color: aqua;
}

with margin doing the spacing or like this with gap

* {
  margin: 0px;
  padding: 0px;
}
#f {
  border: 1px solid blue;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  align-content: flex-start;
  width: 100%;
  gap: 20px;
  min-height: 100vh;
  padding: 10px;
}
#f div {
  border: 1px solid red;
  width: 300px;
  height: 300px;
}
#f div:nth-child(1) {
  background-color: aquamarine;
}
#f div:nth-child(10) {
  background-color: aqua;
}

which of them do you think would give you better responsiveness performance?

tbh cant tell at least based on my example seems to the same

only thing ig i noticed with margin there is more extra space on the main axis

getting confused withe align items and content and justify content

* {
  margin: 0px;
  padding: 0px;
}
#f {
  border: 1px solid blue;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 100vh;
  gap: 20px;
  padding: 10px;
}
#f div {
  border: 1px solid red;
  width: 200px;
  height: 200px;
  /* margin: 20px; */
}
#f div:nth-child(1) {
  background-color: aquamarine;
}
#f div:nth-child(10) {
  background-color: aqua;
}

getting confused i thought justify content centers horiz while items does it vertically, but if i center with content then item seems redundent and not needed. just confused as to when to use them

make a codepen link for it, that way it becomes more interactive for such tasks, happy coding :slight_smile:

1 Like