DESCRIPTION
I have a weird bug where the border causes a small gap between the content and the border itself when set using vmin units.
REPRODUCIBLE SNIPPET
resize the window to see it, as it only happens on some device viewports
body {
display: flex;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
margin: 0;
padding: 0;
}
.container {
display: flex;
width: 80%;
height: 80%;
border-right: 1vmin solid red;
}
.content {
display: flex;
width: 100%;
height: 100%;
background-color: black;
}
<div class="container">
<div class="content" />
</div>
PREMISES
- I'm setting border with
vminunit to keep it consistent between any screen resolution - Elements should keep current structure (border on parent, background on child)
- Both elements should have
display: flex
PROBLEM
I suspect the problem stands on how the vmin value is being rounded into pixels, creating that additional pixel which can be seen in similar scenarios (where a child with the background highlights the gap).
WHAT I TRIED
- By having
display: tables instead offlexfixes the extra px, but this can't be an option as flex is needed vw/vhor any viewport unit generate the same issue
SOLUTION
- A solution for having a flexible border could be to simply set the
.container:afterwith awidthin percentage,heightto 100% and abackground-colorinstead of theborder. This solution works perfectly fine, but it's not a scalable solution in case we require more than just a single border side (e.g.border-right).
CONCLUSION
So premised all this, is there perhaps some trick that can be applied directly to the border (or its element) to get around it?
I'm not concerned about finding the first solution that works; As presented, a solution exists already, so the question is based out of mere curiosity for writing better code.
