html - 自动换行 : break-word not working in <small> or any other element

标签 html css

所以我有这样的代码。但是 word-wrap 不起作用。当我将它更改为 div 但我需要 small 或任何其他元素时它会起作用。那么有什么想法为什么它不起作用并且没有打破这个词吗?

 <small style="width: 15px; word-wrap: break-word;">+{{$s->type }} {{$s->name}}</small>

<small style="width: 15px; word-wrap: break-word;">asfasfassaasfdffgdfgd</small>

www.ibb.co/mkaKrw 这就是它在我的元素中的样子。所以我希望这句话能被打破并流传下来。我不需要内联 block 。所以我想要打破“Tılsımı”这个词。我不确定我想要的东西是否可行,但我只是想问问 css 专家。

最佳答案

<small>默认情况下是内联元素,不会采用任何引用 block 的设置元素,例如 width .所以如果你仍然想保留它并拥有 width设置工作,您必须通过添加 display: block 将其转换为 block 或内联 block 元素或 display: inline-block .我在下面的代码片段中添加了背景颜色以使其更加明显。

<small style="width: 15px; word-wrap: break-word;display:block;background:green;">+{{$s->type }} {{$s->name}}</small>

<small style="width: 15px; word-wrap: break-word;display:inline-block;background:yellow;">asfasfassaasfdffgdfgd</small>

评论后添加:

我想你有这样的情况:

.container {
  width: 90px;
  border: 1px solid #ccc;
}

.container small {
  word-wrap: break-word;
}
<div class="container">
  <p>This is a text that contains some <small>veeeeeeeeeeeerrrrrry</small> long words. This is a text that contains some <small>veeeeeeeeeeeerrrrrry</small> long words. This is a text that contains some <small>veeeeeeeeeeeerrrrrry</small> long words.</p>
</div>

这里是 width适用于容器,不适用于 small , small只围绕长词并包含分词属性,所以它是唯一可以分词的地方:

关于html - 自动换行 : break-word not working in <small> or any other element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48403150/

相关文章:

html - 防止内容垂直扩展网格项

html - 如何在输入复选框中保留边距

html - html中标记宽度的最大值

html - 如何更改鼠标悬停时 HTML 按钮的图像等

css - 悬停改变不透明度

css - Z-index 在 IE8 和 IE7 中不工作

html - 动态调整大小并将 div 放置在容器的末尾(右/底部)

css - 使用 Less 时在 CSS 值中斜线 (`/` )(例如在 `font` 简写中)

html - 为什么我的社交媒体图标没有显示在页脚中?

php - WordPress 博客中的流氓