html - 尽管最小高度为 0,但 Div 在空时仍具有高度

标签 html css twitter-bootstrap bootstrap-4

我正在尝试设计一个 div 的样式,以便调整其高度以适合其中的文本(前提是它不超过其最大高度)。问题是当 div 中没有文本时,div 仍然有一定的高度。

#container {
   width: 80%;
   margin-left: 10%;
   position: absolute;
   bottom: 0;
 }

 #input {
   width: 85%;
   float: left;
 }

 #submit {
   width: 15%;
   display: inline;
   float: right;
 }

 #display {
    display: inline-block;
    margin: 0;
    min-height: 0;
    max-height: 200px;
    width: 100%;
    overflow: scroll;
 }
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" >
<div class="form-group">
    <label for="usr">Terminal:</label><br>
    <input type="text" class="form-control" id="input">
    <button class="btn btn-primary" id="submit">Submit</button>
    <div id="display"></div>
  </div>

我也试过使用 height:0; max-height:200; 但这有相同的结果,当 div 中没有文本时,它仍然有高度并且没有完全消失。

(我正在使用 Bootstrap 4,以防相关)

最佳答案

确保 #display 上的 padding: 0 并在没有 overflow: auto 的情况下尝试。 也试试 box-sizing: border-box

关于html - 尽管最小高度为 0,但 Div 在空时仍具有高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55542308/

相关文章:

javascript - 如何更改显示选项的 HTML5 数据列表背景颜色

jquery - 单击删除完成 <tr>

html - 老掉牙的 IE 问题

javascript - Bootstrap 投票按钮不起作用

jquery - 在多个表行中重复使用下拉菜单

javascript - 使用 JS 函数多次更改 HTML 按钮文本颜色

php - 创建 HTML(PHP 或 Jquery)的最佳实践?

css - Bootstrap - 右侧带有按钮的下拉列表,但表单控件使其宽度为 100%

html - 悬停已经悬停转换的图片时,如何使文本出现?

php - 转储非 ASCII 字符时 DOMDocument 行为不一致的解释是什么?