Removing display:flex adds spaces around a link. Why?

It’s because flexbox remove the default white space between inline or inline-block elements.

Here is a code without flexbox where we have white space:

.box {
  font-size:30px;
}
<div class="box">
  <a>click</a>
  <a>here</a>
</div>

We can remove this white space by removing it from the markup or using any common way:

.box {
  font-size:30px;
}
<div class="box">
  <a>click</a><a>here</a>
</div>

Or by making the div a flexbox container:

.box {
  display:flex;
  font-size:30px;
}
<div class="box">
  <a>click</a>
  <a>here</a>
</div>

If we check the specification:

Each in-flow child of a flex container becomes a flex item, and each
contiguous sequence of child text runs is wrapped in an anonymous
block container flex item. However, if the entire sequence of child
text runs contains only white space (i.e. characters that can be
affected by the white-space property) it is instead not rendered (just
as if its text nodes were display:none).

So in our code we have two child items and a sequence of white space that is not rendred.

Leave a Comment