多行 html 文本区域

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6957480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 09:54:52  来源:igfitidea点击:

multiline html textarea

htmlformsinputtextarea

提问by macaroon5

My form inherits several css styles, and the default display for a textarea only has a single row-- if you type a paragraph it won't wrap but continues going one the same line. How do I force it back to multi-row output? I have set the "rows" and "cols" attributes in the HTML but it doesn't seem to do anything.

我的表单继承了几种 css 样式,并且 textarea 的默认显示只有一行——如果你输入一个段落,它不会换行,而是继续在同一行中。如何强制它返回多行输出?我已经在 HTML 中设置了“行”和“列”属性,但它似乎没有做任何事情。

The HTML is highly nested, but the actual input element is:

HTML 是高度嵌套的,但实际的输入元素是:

<input name="input47" type="textarea" rows="3" cols="10" />

The CSS I've tried is:

我试过的 CSS 是:

body form ol.sections li ol.prompts li ol.entries li ol.inputs li input[type=textarea] {
  height: 500px !important;
  white-space: normal !important;
}

The 500px works regardless whether or not I use !important, but there is only a single line of text in the textarea, vertically centered (Chrome and Safari).

无论我是否使用 500px 都有效!important,但 textarea 中只有一行文本,垂直居中(Chrome 和 Safari)。

EDIT: Clearly I need to brush up on my HTML-- <input type="textarea">should have been <textarea>

编辑:显然我需要复习一下我的 HTML——<input type="textarea">应该是<textarea>

回答by spliter

@macaroon5, you misuse <input />element here. What you want to get is

@macaroon5,你<input />在这里滥用元素。你想要得到的是

<textarea name="input47" rows="3" cols="10">
    Your multiline text is here.
</textarea>

Here is the example

这是例子

回答by mkk

please be aware that except of rows and cols you might also set height and width, which would affect it. It might be the case that you sets rows, but css property height overwrites it.

请注意,除了行和列之外,您还可能设置高度和宽度,这会影响它。可能是您设置了行,但 css 属性高度会覆盖它。

回答by spliter

I assume you have something like

我假设你有类似的东西

white-space: nowrap;

applied to your textarea somewhere in your stylesheet and that's what makes it render the whole chunk of text in one line.

应用于样式表中某处的 textarea,这就是它在一行中呈现整个文本块的原因。

Just add something like

只需添加类似的东西

textarea#myfield {
    white-space: normal
}

There should be no need for !importantin the style above, but if you don't get the result, you can try !important

!important上面的样式应该不需要,但是如果没有得到结果,可以试试!important

回答by hatika dian nurani

using UnityEngine; using System.Collections;

使用 UnityEngine;使用 System.Collections;

public class GameFSM : MonoBehaviour { public enum {LevelAwal, diam, terbang/lompat, objek, pertanyaan, bintang, menembak, menghindar, enemy, nyawa, GameOver, NextLevel}

公共类 GameFSM:MonoBehaviour { public enum {LevelAwal、diam、terbang/lompat、objek、pertanyaan、bintang、menembak、menghindar、敌人、nyawa、GameOver、NextLevel}

public TurnStates state;
public bool gameInProgress = true;

void Start () {
    state = GameFSM.Mulai.Init;
    StartCoroutine ("TurnFSM");
}
private IEnumerator TurnFSM (){
    while(gameInProgress){
        switch(state){
        case TurnStates.LevelAwal:
            if( Permainan Awal()) {* state = diam:}
            break;
        case TurnStates.diam:
            if(Mulai()) {* state =lompat/terbang;}
            break;
        case TurnStates.Jump:
            if( Melompat()) {* state = objek;}
            break;
        case TurnStates.benda:
            if( mencari objek()) {* state = pertanyaan;}
            if (menghindar ()) {* state = enemy;}
            break;
        case TurnStates.objek:
            if( mencari Benda ()) {* state = pertanyaan;}
            if(Menembak()) {* state = enemy;}
            break;
        case TurnStates.enemy:
            if( Terkena Enemy ()) {* state = nyawa;}
            Break;
        case TurnStates.soal:
            if( benar ()) {* state = k;}
            else (salah ()) {* state = nyawa;}
            break;
        case TurnStates.nyawa:
            if(nyawa masih tersedia ()) {* state = diam;}
            else (nyawa masih habis ()) {* state = GameOver;}
            Break;
        case TurnStates.Kunci:
            if( berhasil menjawab()) {*state = NextGame;}
            break;
        case TurnState.NextGame :
            if (DoneLevel ()) {* state = LevelBaru;}
            break;
        }
        yield return null;
    } 
}