Home > Back-end >  Can't make string make box resize to size of String
Can't make string make box resize to size of String

Time:11-25

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. :x

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 >
      <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. :)

CodePudding user response:

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;
...    
}
  • Related