2

The baseline and flex-start values for align-items doesn't shows any variations between. I am unable to differentiate between both values because both works same. The code which I used to differentiate between baseline and flex-start is:

div {
  border-right: 1px solid #ff0;
  width: 12vh;
  background-color: orange;
}

.container div:nth-child(1) {
  height: 100px;
}

.container div:nth-child(2) {
  height: 50px
}

.container {
  height: 130px;
  border: 2px solid red;
  display: flex;
}

#st {
  flex-direction: row;
  align-items: baseline;
}

#nd {
  flex-direction: row;
  align-items: flex-start;
}
<section class=container id=st>
  <div>1</div>
  <div>2</div>
  <div>3</div>
</section>
<section class=container id=nd>
  <div>1</div>
  <div>2</div>
  <div>3</div>
</section>

what is the difference between baseline and flex-start. Editing my code such that baseline and flex-start shows difference is very helpful if you want to answer my question

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
Hash
  • 556
  • 5
  • 17

1 Answers1

2

In this particular case the visual is the same because the reference for each alignement is the same. Here is an illustration to better understand:

enter image description here

As you can see the baseline is defined by the text inside. Since you are using the same font-family, font-size, line-height,etc and you have one line of text then the baseline is the same for the 3 boxes thus you will have the same result as flex-start.

Change the baseline of one element by increasing font-size for example and you will notice the difference:

div {
  border-right: 1px solid #ff0;
  width: 12vh;
  background-color: orange;
}

.container div:nth-child(1) {
  height: 100px;
}

.container div:nth-child(2) {
  height: 50px;
  font-size: 25px;
}

.container {
  height: 130px;
  border: 2px solid red;
  display: flex;
}

#st {
  flex-direction: row;
  align-items: baseline;
}

#nd {
  flex-direction: row;
  align-items: flex-start;
}
<section class=container id=st>
  <div>1</div>
  <div>2</div>
  <div>3</div>
</section>
<section class=container id=nd>
  <div>1</div>
  <div>2</div>
  <div>3</div>
</section>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415