0

I've created this example:

.container {
  height: 50px;
  display: flex;
  flex-wrap: nowrap;
  overflow-x: scroll;
  padding-top: 3px;
  padding-bottom: 3px;
  padding-left: 6px;
  padding-right: 6px;
  background: lightgray;
}

.card {
  min-width: 200px;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px solid white;
  margin-top: 0px;
  margin-bottom: 0px;
  margin-left: 3px;
  margin-right: 3px;
}

.card-final {
  padding-right: 6px;
}
<div class="container">
  <div class="card">Cat</div>
  <div class="card">Tropical fish</div>
  <div class="card">Southern Titiwangsa bent-toed gecko</div>
  <div class="card">Woodpecker</div>
  <div class="card">Crow</div>
  <div class="card">Peacock</div>
  <div class="card">Pig</div>
  <div class="card">Dog</div>
  <div class="card-final"></div>
</div>

What I would like to have is that the .cards have no fixed width the text inside each card should be on a single line and each card shouldn't have more horizontal space that the necessary. So the Pig card will have smaller width than then the Tropical fish card or the Southern Titiwangsa bent-toed gecko card.

0

1 Answer 1

1

Remove the min-width and use flex-shrink:0;

.container {
  height: 50px;
  display: flex;
  flex-wrap: nowrap;
  overflow-x: scroll;
  padding-top: 3px;
  padding-bottom: 3px;
  padding-left: 6px;
  padding-right: 6px;
  background: lightgray;
}

.card {
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px solid white;
  margin-top: 0px;
  margin-bottom: 0px;
  margin-left: 3px;
  margin-right: 3px;
  flex-shrink:0;
}

.card-final {
  padding-right: 6px;
}
<div class="container">
  <div class="card">Cat</div>
  <div class="card">Tropical fish</div>
  <div class="card">Southern Titiwangsa bent-toed gecko</div>
  <div class="card">Woodpecker</div>
  <div class="card">Crow</div>
  <div class="card">Peacock</div>
  <div class="card">Pig</div>
  <div class="card">Dog</div>
  <div class="card-final"></div>
  <div class="card">Crow</div>
  <div class="card">Peacock</div>
  <div class="card">Pig</div>
  <div class="card">Dog</div>
  <div class="card">Crow</div>
  <div class="card">Peacock</div>
  <div class="card">Pig</div>
  <div class="card">Dog</div>
</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.