如何在提交输入框中添加换行符

14
我正在寻找一种方法,在两行中显示一个 <input type="submit"> 的值,因此可能会在其中添加一个换行符,但我尝试了多种方法,例如:

  • <br>
  • \r\n
  • \n
  • &#10;

结果应该像这样(图片右侧):

the result

没有任何作用。 有人对此有什么线索吗?

5个回答

14
将以下内容添加到你的css样式表中: white-space属性可以让输入框支持多行文本。

input[type="submit"] {
    white-space: normal;
    width: 150px;
    float:right;
    text-align: right;
}
<input type="submit" value="J'essaie gratuitement 30 jours" />

另外还有两种方法:

<button type="submit">Multiple line<br/>input</button>

并且

在输入值之间使用&#13;&#10;回车符:

<input type="button" value="Multiple line&#13;&#10;input" style="text-align:center;">

然而,最后一种方法在IE10中不起作用。


11
使用 button 代替 input:

.right-aligned {
  text-align: right;
}
<button type="submit" class="right-aligned">Text <br /> broken </button>

按钮可以接受其他各种标签,例如<br /><span>

然后,您可以使用CSS按照自己的意愿对其进行样式设置(请参见代码片段中的CSS类和规则)。


3
我认为你可以在HTML中尝试这个:
这只是一个例子,帮助你理解:

<input type="button" value="Really&#x00A;Tall&#x00A; Button">


2
这对我有用:

这是对我有效的:

div.full {
  width:500px;
  background-color:grey;
}

div.left {
  float:left;
  width:60%
}

button {
  width:40%;
  text-align:right;
  cursor:pointer;
}

div.underline {
  width:100%;
}
<div class='full'>
  <div class='left'>
    there is a part of text
  </div>
  <button>J'essaie gratuitement
    <div class='underline'>30 jours</div>
  </button>
</div>

我刚刚添加了一些CSS来保持按钮的大小。而换行并不是一个很好的做法。最好使用CSS来处理。



网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接