I have a flexbox container with several divs with a gap of about 8px. When I reduce the width causing the text to wrap, the gap increases.
.container {
width: 290px;
gap: 8px;
display: flex;
}
.block {
background: red;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Document</title>
</head>
<body>
<div class="container">
<div class="block">First Second ThirdFourthFifth</div>
<div class="block">Block 2</div>
<div class="block">Block 3</div>
</div>
</body>
</html>
I would expect there not to be the extra space on the right of the text when wrapped, as shown in the following: Expectation
I have tried width: min-content
, but this forces the text to always wrap, which I do not want. I want the text to be in one line if it fits. For this purpose I have tried whitespace: nowrap
. However, I also want the text to wrap if the width is constrained.