javascript - 工具提示自动换行问题

标签 javascript html twitter-bootstrap

工具提示是自动换行,文本溢出到换行符。如何解决这个问题,我更喜欢以单行而不是多行显示文本?这里是 JSBin

<html>
<head>
<script src="http://code.jquery.com/jquery.min.js"></script>
<link href="http://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet" type="text/css" />
<script src="http://getbootstrap.com/dist/js/bootstrap.js"></script>
<script src="http://twitter.github.com/bootstrap/assets/js/bootstrap-tooltip.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <script>
$(document).ready(function(){
    $('[data-toggle="tooltip"]').tooltip();
});
</script>
  <div class="form-group">
                <label class="col-xs-2 control-label">Name</label>
                <div class="col-xs-5">
                    <input type="text" class="form-control" name="name" data-toggle="tooltip" title="Lorem ipsum dolor" data-placement="right"/>
                </div>    
            </div>
</body>
</html>

最佳答案

应用 CSS white-space: nowrap;抑制字符串中的换行符。

.tooltip{
  white-space: nowrap;
}

.tooltip {
  white-space: nowrap !important;
}
<html>

<head>
  <script src="http://code.jquery.com/jquery.min.js"></script>
  <link href="http://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet" type="text/css" />
  <script src="http://getbootstrap.com/dist/js/bootstrap.js"></script>
  <script src="http://twitter.github.com/bootstrap/assets/js/bootstrap-tooltip.js"></script>
  <meta charset=utf-8 />
  <title>JS Bin</title>
</head>

<body>
  <script>
    $(document).ready(function() {
      $('[data-toggle="tooltip"]').tooltip();
    });
  </script>
  <div class="form-group">
    <label class="col-xs-2 control-label">Name</label>
    <div class="col-xs-5">
      <input type="text" class="form-control" name="name" data-toggle="tooltip" title="Lorem ipsum dolor" data-placement="right" />
    </div>
  </div>
</body>

</html>

关于javascript - 工具提示自动换行问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38736461/

相关文章:

javascript - 如果瞄准镜没用了,会被清理吗?

javascript - Chrome 中的文件上传

html - 每个新的 div 都会缩小行宽,即使每个 div 都是完整的 12 列

html - Bootstrap - 为什么我需要两个类来设置按钮样式?

jquery - 隐藏 Boostrap 列表组元素

javascript - 你如何追加一个元素,同时又保持它在原来的位置?

javascript - ComponentWillUnmount 没有被调用 React-Navigation

javascript - 如何设置 HTML 选择选项悬停和选定选项效果的样式

html - 样式不考虑没有按钮

php - 如何使用 PHP 生成较浅/较深的颜色?