html - 如何用两个 50% 表格单元格拆分单词?

标签 html css cell css-tables

我正在尝试分解两个 50% 宽度单元格的表格中的长单词。 我已经尝试过 word-wrap: break-word; 但它没有帮助。

HTML

<section class="table-wrapper">
    <section class="table-left">
        <p>LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG</p>
    </section>
    <section class="table-right">
        <p>SHOOOOOOOOOOOOOOOOOOORT</p>
    </section>
</section>

CSS

.table-wrapper {
    display:table;
    border-collapse:separate;
    border-spacing:5px 5px;
    width: 100%;
}

.table-left, .table-right {
    display: table-cell;
    width: 50%;
}

Jsfiddle: http://jsfiddle.net/Lu50tLmf/

它破坏了整个元素的大小,如果单词太长,它就太大了。我该如何解决这个问题?

最佳答案

您可以使用word-break属性。

Allow long words to be able to break and wrap onto the next line

.table-left、.table-right中:

删除display:table-cell;

添加word-break:break-all;

更改为:

.table-wrapper {
    display:table;
    border-collapse:separate;
    border-spacing:5px 5px;
    width: 100%;
}

.table-left, .table-right {
    width: 50%;
    word-break:break-all;
}

<强> JSFiddle Demo

关于html - 如何用两个 50% 表格单元格拆分单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25292082/

相关文章:

html - 在没有文本的 float 元素上总是有宽度

php - HTML PHP 登录成功后显示用户名

html - CSS:为什么 Chrome 和 Firefox 中的颜色代码 #999 色调不同?

css - Bootstrap 破坏了生产中的行单元格

ios - 我无法将 TableViewCell 按钮连接到 TableViewController!如何将值从 TableViewCell 连接到 TableViewController?

html - 在 Cocoa 中打开 HTML 源代码

javascript - 如何创建可以出现在 opencart 门户屏幕底部的通知对话框

php - 将类 img-responsive 添加到 wordpress 中所有附加的帖子图像

PHP选择具有特定宽度的图像并构建网格

excel - 如何使用键盘在Excel单元格中下拉菜单?