我如何在 div 的底部开始文本?

How would I start text at the bottom of the div?

所以我正在做一个关于基于终端的“进度”的项目,我想制作终端在 Linux/MacOS 等中出现的效果。现在,文本停留在顶部并得到按下 Enter 键时替换。有没有办法在底部创建一条新线并将旧线向上移动?谢谢!

这是我目前正在使用的 CodePen 项目的 link。 https://codepen.io/ZacV/pen/abEYpLz '''

function onKeyPressed(e) {
    var keyCode = e.keyCode;
    var key = e.key;
    var currentText;
    if (keyCode == 13){
      currentText = document.getElementById("Input").value;
      textfield.push(currentText);
      $("#Input").val("");
      // document.getElementById("Output").innerHTML = textfield;
      document.getElementById("Output").innerHTML = "Did not understand field: " + textfield[textfield.length-1];
    };
}

'''

你可以使用 bottom 属性 来对齐终端底部的 h3 div

然后使用

$("#Output").append(currentText + '<br/>');

将用户输入的新文本附加到输出

不要忘记在 terminalBody 和 h3 上使用 overflow: hidden; 来隐藏超出输出大小的行

feather.replace();

document.addEventListener("keydown", onKeyPressed);

var textfield = [];

function onKeyPressed(e) {
  var keyCode = e.keyCode;
  var key = e.key;
  var currentText;
  if (keyCode == 13) {
    currentText = document.getElementById("Input").value;
    textfield.push(currentText);
    $("#Input").val("");
    $("#Output").append(currentText + '<br/>');
  };
}
:root {
  /*colors */
  --grey: rgb(50, 50, 50);
  --secondgrey: rgb(40, 40, 40);
  --green: rgb(30, 180, 30);
}

body {
  background-color: var(--grey);
  font-family: 'Courier New', monospace;
}

.stats {
  position: absolute;
  background-color: var(--secondgrey);
  top: 10px;
  width: 150px;
  height: 180px;
  outline-color: var(--green);
  outline-width: 3px;
  outline-style: solid;
}

.stats .statsLabel {
  position: relative;
  left: 10px;
  top: -10px;
  color: grey;
}

.stats .statsMoney {
  position: absolute;
  left: 10px;
  top: 20px;
  color: var(--green);
}

.stats .statsStatus {
  position: absolute;
  left: 10px;
  top: 40px;
  color: purple;
}

.stats .statsRole {
  position: absolute;
  left: 10px;
  top: 60px;
  color: red;
}

.stats .statsLevel {
  position: absolute;
  left: 10px;
  top: 80px;
  color: blue;
}

.stats .statsControl {
  position: absolute;
  left: 10px;
  top: 100px;
  color: Orange;
}


/* Stats Display */

.stats .DispLabel {
  position: relative;
  right: 10px;
  top: -10px;
  color: grey;
}

.stats .DispMoney {
  position: absolute;
  right: 10px;
  top: 20px;
  color: var(--green);
}

.stats .DispStatus {
  position: absolute;
  right: 10px;
  top: 40px;
  color: purple;
}

.stats .DispRole {
  position: absolute;
  right: 10px;
  top: 60px;
  color: red;
}

.stats .DispLevel {
  position: absolute;
  right: 10px;
  top: 80px;
  color: blue;
}

.stats .DispControl {
  position: absolute;
  right: 10px;
  top: 100px;
  color: Orange;
}

.stats .DispLink {
  position: absolute;
  left: 10px;
  bottom: 10px;
  color: grey;
  font-size: 15px;
}

.terminalBody {
  position: absolute;
  width: auto;
  left: 170px;
  right: 10px;
  height: auto;
  top: 10px;
  bottom: 10px;
  background-color: var(--secondgrey);
  outline-color: var(--green);
  outline-width: 3px;
  outline-style: solid;
  overflow: hidden;
}

.terminalBody .terminalInput {
  position: absolute;
  left: 60px;
  width: calc(100% - 67.5px);
  height: 40px;
  bottom: 0px;
  top: auto;
  outline-color: var(--green);
  outline-width: 3px;
  outline-style: solid;
  background-color: var(--grey);
  color: var(--green);
  font-size: 17px;
}

.terminalBody svg {
  position: absolute;
  width: 40px;
  height: 40px;
  left: 10px;
  bottom: 6px;
  top: auto;
  color: var(--green);
}

.terminalBody h3 {
  position: absolute;
  color: var(--green);
  left: 60px;
  height: auto;
  bottom: 40px;
  font-size: 17px;
  font-size: 17px;
  line-height: 29px;
  overflow: hidden;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/feather-icons/4.29.0/feather.js" integrity="sha512-0hV9FhQc44B5NIfBhQFNBTXrrasLwG6SVxbRiaO7g6962sZV/As4btFdLxXn+brwH7feEg3+AoyQxZQaArEjVw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<!-- among us -->
<div class="stats">
  <h3 class="statsLabel">Stats:</h3>
  <h3 class="statsMoney">Money</h3>
  <h3 class="statsStatus">Status</h3>
  <h3 class="statsRole">Role</h3>
  <h3 class="statsLevel">Level</h3>
  <h3 class="statsControl">Control</h3>

  <h3 class="DispMoney">0</h3>
  <h3 class="DispStatus">N/A</h3>
  <h3 class="DispRole">N/A</h3>
  <h3 class="DispLevel">0</h3>
  <h3 class="DispControl">0</h3>
  <a href="https://codepen.io/ZacV" class="DispLink">Made by Zacc</a>
</div>
<div class="terminalBody">
  <input type="text" class="terminalInput" id="Input">
  <i data-feather="chevron-right"></i>
  <h3 class="Output" id="Output"></h3>
</div>