【问题标题】:Fit to content for Bootstrap alert [duplicate]适合引导警报的内容[重复]
【发布时间】:2015-09-29 07:28:18
【问题描述】:

我有一个引导警报,我希望宽度适合内容。在 Bootstrap 文档中,默认设置为 100% 宽度。使警报的内容完全适合所有屏幕尺寸的最可靠方法是什么?

<div class="container">
    <div class="alert alert-danger">
        My short alert message.
    </div>
</div>

【问题讨论】:

  • 副手,我不知道“一些 CSS”会适合它的内容。此外,也许有一个内置的 Bootstrap 类可以做到这一点?我通过搜索文档找不到一个。
  • 开始使用浏览器的检查器并尝试一些东西。我建议从浮动开始,或者将其转换为内联块元素。 SO 并不是真正的“写代码,因为我不想尝试”的地方。

标签: css twitter-bootstrap


【解决方案1】:

您只需添加display: inline-block

堆栈片段中的演示:

.alert-trim {
  display: inline-block;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.css">

<div class="container">
  <div class="alert alert-danger">
    Normal Alert Message
  </div>

  <div class="alert alert-danger alert-trim">
    Trimmed Alert Message
  </div>
</div>

另见Is it really impossible to make a div fit its size to its content?

【讨论】:

  • 如果所有的答案都这么简单和直截了当!谢谢。
  • 很高兴它有帮助! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-17
  • 2021-01-29
  • 2018-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多