1

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.

franklbf
  • 11
  • 2
  • Could you please edit this post and try to use the HTML/JS/CSS snippet to reproduce your issue? You can use dummy text and images to reproduce a similar component to what you are trying to create. Otherwise these resources may help:- https://flexboxfroggy.com/ and https://css-tricks.com/snippets/css/a-guide-to-flexbox/ – Shane Muirhead Jan 31 '23 at 17:16
  • you cannot do this – Temani Afif Jan 31 '23 at 21:51

0 Answers0