【问题标题】:Can't make string make box resize to size of String无法使字符串使框调整大小以适应字符串的大小
【发布时间】:2022-11-25 05:04:24
【问题描述】:

如您所见,我希望该框能够响应相对于 String 在本例中为数字的行为。 Photo

我还不能发布照片。 :X

我在这里添加我的代码。我试图对 CSS 进行一些更改,但我无处可去,所以我在这里寻求帮助。

<!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;
}

我只是写了更多的话,所以我可以发布这个问题,不要费心看我在这里写的东西,谢谢。 :)

【问题讨论】:

    标签: css string responsive-design


    【解决方案1】:

    只需更改CSS:

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

    至:

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

    如果您仍希望最小宽度为 250 像素:

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

    【讨论】:

      猜你喜欢
      • 2016-09-17
      • 2017-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-15
      相关资源
      最近更新 更多