Html 按钮内的文本换行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19309803/
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
text wrap inside a button
提问by Anuj Hari
I have 4 a
-tags. Everything in each of the CSS works. It resizes the buttons perfectly on my phone. The only problem I have is on my phone, for the login/register button, the text cuts of inside the button and all it shows is login/register.
我有 4 个a
标签。每个 CSS 中的所有内容都有效。它可以完美地调整我手机上的按钮大小。我唯一的问题是在我的手机上,对于登录/注册按钮,按钮内部的文本剪切以及它显示的只是登录/注册。
From what I recall white-space: normal
is the way to do this, but maybe I am wrong.
据我回忆white-space: normal
是这样做的方式,但也许我错了。
@media only screen and (max-device-width: 480px) {
.newsButton {
width: 49%;
height: 140px;
white-space: normal;
float: left;
}
.venueButton {
width: 49%;
height: 140px;
white-space: normal;
float: right;
}
.learnButton {
width: 49%;
height: 140px;
white-space: normal;
float: left;
}
.loginButton {
width: 49%;
height: 140px;
white-space: normal;
float: right;
}
}
<a href="menu.php" class="newsButton" data-role="button" data-theme="e">News</a>
<a href="venue.php" class="venueButton" data-role="button" data-theme="e">Venue Hire</a>
<a href="learn.php" class="learnButton" data-role="button" data-theme="e">Learn</a>
<a href="login.php" class="loginButton" data-role="button" data-theme="e">Login/Register</a>
回答by Kevin Pei
I believe you use word-wrap: break-word;
. Also, remove the height
restrictions - it'll just cause weird text overflow issues when the word wraps to a new line.
我相信你用word-wrap: break-word;
. 此外,删除height
限制 - 当单词换行到新行时,它只会导致奇怪的文本溢出问题。
@media only screen and (max-device-width: 480px) {
.newsButton{
width:49%;
word-wrap:break-word;
float: left;
}
.venueButton{
width:49%;
word-wrap:break-word;
float: right;
}
.learnButton{
width:49%;
word-wrap:break-word;
float: left;
}
.loginButton{
width:49%;
word-wrap:break-word;
float: right;
}
}
Also you seem to be using your classes in a really odd fashion. Shouldn't you be assigning those classes as id
's and giving all the buttons one button
class like so?
HTML
此外,您似乎以一种非常奇怪的方式使用您的课程。难道您不应该将这些类分配为id
's 并button
像这样为所有按钮分配一个类吗?
HTML
<a href="menu.php" id="newsButton" class="button" data-role="button" data-theme="e">News</a>
<a href="venue.php" id="venueButton" class="button" data-role="button" data-theme="e">Venue Hire</a>
<a href="learn.php" id="learnButton" class="button" data-role="button" data-theme="e">Learn</a>
<a href="login.php" id="loginButton" class="button" data-role="button" data-theme="e">Login/Register</a>
CSS:
CSS:
@media only screen and (max-device-width: 480px) {
.button{
width:49%;
word-wrap:break-word;
float: left;
}
}
回答by gilbert-v
The issue is: a
tags are display: inline
by default. word-wrap: break-word
doesn't work on any element that isn't display: inline-block
or display: block
(see this).
问题是:a
标签是display: inline
默认的。word-wrap: break-word
不适用于任何不是display: inline-block
或的元素display: block
(请参阅此)。
As a result, you must your button like so
结果,你必须像这样你的按钮
.button {
// ...
display: inline-block;
word-wrap: break-word;
// ...
}
Hope this helps.
希望这可以帮助。