按下回车键/返回键时,我似乎丢失了默认的textarea行为。我希望按键将光标移动到下一行,但它只是插入几个空格。必须是我的css规则中的东西,但我不知道它是什么。
button, input, textarea, select {
outline: none;
box-shadow: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
-webkit-border-radius: 0;
border-radius: 0;
color: #3b3b3b;
font-family: inherit;
font-size: inherit;
text-decoration: none;
display: inline-block;
white-space: nowrap;
margin: 0;
padding: 0.2em 0.4em;
width: 100%;
-webkit-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
border-width: 1px;
border-style: solid;
border-color: #d4d4d4;
background: #fff;
}
textarea {
height: 8em;
vertical-align: top;
overflow: auto;
}
<textarea id="Textarea1" placeholder="Text area"></textarea>
答案 0 :(得分:2)
删除第14行的white-space: nowrap;
。
答案 1 :(得分:0)
更新:我发现textarea的默认行为是white-space: pre;
,所以我更新了我的CSS规则如下,现在工作正常:
button, input, textarea, select {
outline: none;
box-shadow: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
-webkit-border-radius: 0;
border-radius: 0;
color: #3b3b3b;
font-family: inherit;
font-size: inherit;
text-decoration: none;
display: inline-block;
white-space: nowrap;
margin: 0;
padding: 0.2em 0.4em;
width: 100%;
-webkit-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
border-width: 1px;
border-style: solid;
border-color: #d4d4d4;
background: #fff;
}
textarea {
height: 8em;
vertical-align: top;
overflow: auto;
white-space: pre;
}
&#13;
<textarea id="Textarea1" placeholder="Text area"></textarea>
&#13;