Can't make string make box resize to size of String

Issue

As you can see, I would like the box to behave responsive relative to String in in this case a number.
Photo

I can’t post photos yet. 😡

Here i’m adding my code. I tried to make some changes in CSS but I was going nowhere so here I am asking for help.

<!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="./styles.css">
  <title>Fun with JS</title>
</head>

<body>
  <h1>Learning area for JS.</h1>
  <container>
    <div class="flex-container">
      <h1 id="count-el">0</h1>
    </div>
    <button type="button" id="increase-btn" onclick="increaseNumber()">Increase</button>
    <button type="button" id="decrease-btn" onclick="decreaseNumber()">Decrease</button>
    <button type="button" id="save-btn" onclick="save()">Save</button>
    <button type="button" id="reset-btn" onclick="reset()">Reset</button>

    <script src="index.js"></script>
  </container>
</body>

</html>
body {
  background-color: bisque;
  text-align: center;
  font-size: 16px;
}

button {
  border: 2px solid;
  height: 40px;
  width: 100px;
  color: black;
  background-color: azure;
  font-size: 1.2em;
}

button:hover {
  background-color: grey;
}

.flex-container {
  display: flex;
  justify-content: center;
  max-width: 500px;
  width: 250px;
  height: auto;
  background-color: black;
  margin: 10px auto;
  color: white;
  border-radius: 5px;
}

.flex-container h1 {
  font-size: 15em;
  margin: 0;
}

Im just writing some more words so i can post this question, dont bother looking at what im writing here, thanks. 🙂

Solution

Just change in css:

.flex-container {
...
width: 250px;    
...
}

to:

.flex-container {
...
width: fit-content;
...    
}

if You want to still have a minimum width of 250px:

.flex-container {
...
min-width: 250px;
width: fit-content;
...    
}

Answered By – PolishFuze

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published