文本应以两行显示

时间:2017-04-04 14:04:00

标签: html css

我需要在两行中显示标题。 就像它在下面的图像中所示。第二项是好的,但第一项是即将到来的是我不想要的单行

.ms-tileview-tile-titleTextMediumCollapsed {
    width: 120px !important;
    top: 80px !important;
    -webkit-transition: top 0.5s ease-out;
    -moz-transition: top 0.5s ease-out;
    -o-transition: top 0.5s ease-out;
    text-align:center;
    line-height: 1.5em;
    height: 3em;
    overflow: hidden; 
}
<div class="ms-tileview-tile-titleTextMediumCollapsed">Group Members</div>
<div class="ms-tileview-tile-titleTextMediumCollapsed">Temp Document Library</div>

4 个答案:

答案 0 :(得分:2)

您可以更改宽度:

width: 80px !important;

这很重要吗?

如果您不想更改宽度,可以在标题中间添加<br/>

<div class="ms-tileview-tile-titleTextMediumCollapsed">Group <br/> Members</div>

答案 1 :(得分:2)

虽然leo的答案简单而优雅,但这是另一种方法。

.ms-tileview-tile-titleTextMediumCollapsed {
    top: 80px !important;
    -webkit-transition: top 0.5s ease-out;
    -moz-transition: top 0.5s ease-out;
    -o-transition: top 0.5s ease-out;
    text-align:center;
    line-height: 1.5em;
    height: 3em;
    overflow: visible; 
    word-wrap: break-word; // word break with overflow display
    max-width: 120px;
}

请查看链接。

https://jsfiddle.net/sarojsasmal/6ce9ym4n/4/

答案 2 :(得分:0)

您可以通过更改元素宽度轻松实现此目的。 但如果您不想弄乱宽度,那么简单的解决方案就是使用paddingbox-sizing: border-box属性。

像这样:

&#13;
&#13;
.ms-tileview-tile-titleTextMediumCollapsed {
    width: 120px !important;
    top: 80px !important;
    -webkit-transition: top 0.5s ease-out;
    -moz-transition: top 0.5s ease-out;
    -o-transition: top 0.5s ease-out;
    text-align:center;
    line-height: 1.5em;
    height: 3em;
    overflow: hidden; 
    padding: 0 20px;
    box-sizing: border-box;
}
&#13;
<div class="ms-tileview-tile-titleTextMediumCollapsed">Team Members</div>
<div class="ms-tileview-tile-titleTextMediumCollapsed">Draft Document Library</div>
&#13;
&#13;
&#13;

答案 3 :(得分:0)

所以你想要&#34;团队成员&#34;在两条线上?但保留其他所有内容?

我会将这些单词包装在一个包装器中,这样你就不必在任何菜单项上重复该类。我不知道你可以自定义多少html,但这对你来说可能更好:

<强> HTML

<div class="title-container">
    <span class="two-line-title">Team Members</span>
    <span>Draft Document Library</span>
</div>

<强> CSS

.title-container {
    width: 120px !important;
    top: 80px !important;
    text-align:center;
    line-height: 1.5em;
    overflow: hidden;
    transition: top 0.5 ease-out; 
}

.title-container span {
    display: block;
    margin: 0 auto;
}

.two-line-title {
    width: 70px !important;
    line-height: 1.2em;
}

http://codepen.io/StefanBobrowski/pen/ryRRRv