我有一个 4 行 20 列的文本区域。我希望光标从左下角开始。当我向文本区域写入内容时,文本会上升。我可以为此编写任何 css 代码吗?
最佳答案
这是一个简化的解决方案,适用于行数是静态的情况。该解决方案给人的印象是在隐藏输入字段时有一个文本区域元素(删除了每个文本输入周围的边框)。
<head>
<script>
function goUpOneRow( e, row ){
if (e.keyCode == 13) {
document.getElementById( row ).focus();
}
}
</script>
<style>
#inputarea {
border:1px solid #ccc;
width:300px;
height:150px;
}
#inputarea input {
width:100%;
height:25%;
font-size:18px;
border: 0;
outline-width: 0;
}
</style>
</head>
<body>
<div id="inputarea">
<div><input id="row1" type="text"> </div>
<div><input id="row2" type="text" onKeyPress="goUpOneRow( event, 'row1' );"> </div>
<div><input id="row3" type="text" onKeyPress="goUpOneRow( event, 'row2' );"> </div>
<div><input id="row4" type="text" autofocus onKeyPress="goUpOneRow( event, 'row3' );"> </div>
</div>
</body>
关于css - 文本区域中的垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59546229/