输入按钮内的中心文本

时间:2016-08-22 05:21:47

标签: html css3 input

我有一个带有文本的输入按钮 - 我希望文本适合输入按钮(意思是,如果它不合适,它会在2或3行上传播)。



<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<style>
.blankbtn
{
text-align:center;
font-size:20px;
width:150px;
height:150px;
background-image: url(http://thumbnails.billiondigital.com/200/930200/794615_small_checkboard.jpg);
background-repeat:no-repeat;
 
}
</style>
<input type="button" value="heres a long text" class="blankbtn"/>

</body>
</html>
&#13;
&#13;
&#13;

有什么建议吗?

3 个答案:

答案 0 :(得分:1)

添加此css

white-space: pre-line;

答案 1 :(得分:0)

使用white-space:normal;

&#13;
&#13;
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<style>
.blankbtn
{
text-align:center;
font-size:20px;
width:150px;
height:150px;
background-image: url(http://thumbnails.billiondigital.com/200/930200/794615_small_checkboard.jpg);
background-repeat:no-repeat;
  white-space: normal;
 
}
</style>
<input type="button" value="heres a long text" class="blankbtn"/>

</body>
</html>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

使用:

word-wrap: break-word;      /* IE 5.5-7 */
white-space: -moz-pre-wrap; /* Firefox 1.0-2.0 */
white-space: pre-wrap;      /* current browsers */

它适用于IE。点击此处 white-space 向下滚动到浏览器兼容性

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<style>
.blankbtn
{
text-align:center;
font-size:20px;
width:150px;
height:150px;
background-image: url(http://thumbnails.billiondigital.com/200/930200/794615_small_checkboard.jpg);
background-repeat:no-repeat;
word-wrap: break-word;      /* IE 5.5-7 */
white-space: -moz-pre-wrap; /* Firefox 1.0-2.0 */
white-space: pre-wrap;      /* current browsers */
 
}
</style>
<input type="button" value="heres a long text" class="blankbtn"/>

</body>
</html>