White space: nowrap with flex: 1; child width is too small to accommodate text
P粉776412597
P粉776412597 2023-09-04 13:30:47
0
1
395
<p>I can't find any solution to have 2 equally sized divs fit the text in one line. Looks like whitespace: after I set parent width:fit-content, width is not taken into account now. </p> <p>They should be as small as possible, always the same size, and do not wrap the text to the second line. </p> <p> <pre class="brush:css;toolbar:false;">div { display: flex; width: fit-content; } .button { padding: 10px 20px; flex: 1; white-space: nowrap; min-width: 130px; width: fit-content; } .button1 { background: red; } .button2 { background: green; }</pre> <pre class="brush:html;toolbar:false;"><div> <div class="button button1">Short Text</div> <div class="button button2">A Long Text Button That Has Greater Width </div> </div></pre> </p>
P粉776412597
P粉776412597

reply all(1)
P粉156532706

Can be done using CSS Grid:

.container {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
}

.button {
  padding: 10px 20px;
  white-space: nowrap;
  min-width: 130px;
  overflow: auto;
}

.button1 {
  background: red;
}

.button2 {
  background: green;
}
<div class="container">
  <div class="button button1">Short Text</div>
  <div class="button button2">A Long Text Button That Has Greater Width </div>
</div>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!