html - 在一行中显示按钮内的文本

标签 html css twitter-bootstrap

我有一个按钮,里面有一些文本,它在一行中显示文本,这没问题,但是当我使用 display:block 将按钮居中时,按钮居中,这很好但是里面的文字有一个换行符,分为两行,我希望文字只显示在一行中: 这是我的代码:

<div class="MyClass"><a type="button" style="margin:auto; display:block" class="ButtonLink" href="@Url.Action("MyAction","MyController")">Selected Now</a></div>

当我有这样的代码时,文本显示在一行中,但我需要将按钮居中:

<div class="MyClass"><a type="button" class="ButtonLink" href="@Url.Action("MyAction","MyController")">Selected Now</a></div>

这就是我想要的:

enter image description here

这就是当我将按钮居中时文本的显示方式:

enter image description here

我需要做什么?

最佳答案

您需要添加white-space: nowrap

<div class="MyClass">
    <a type="button" class="ButtonLink" href="@Url.Action("MyAction","MyController")">Selected Now</a>
</div>
.ButtonLink {
  white-space: nowrap;
  text-align: center;
}

关于html - 在一行中显示按钮内的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41103100/

相关文章:

javascript - CSS Bootstrap 通过 javascript 创建元素

javascript - 如何将 HTML 文本区域放入 JavaScript Web 警报/弹出窗口中?

html - 在图像顶部显示导航栏无法正常工作

html - 定位在模态窗口外时图像被截断

javascript - 移动图像和文本 - Javascript + html

jquery - CSS 背景具有无效的属性值

javascript - 如何在 meteor 项目中 Bootstrap 之前调用 jquery-ui 以防止冲突

html - 如何限制用户在html文本字段中只能输入小数点后一位数字

html - Blockquote 引用符号在内容框外流血

css - bootstrap 字体文件夹中哪些字体是真正必不可少的