【发布时间】:2017-11-09 20:59:42
【问题描述】:
我有一个类似于下面header 的网格布局。 div 中有一个宽度为1fr 的文本。我希望该 div 内的文本在太长时被截断。将text-overflow 添加为ellpsis 不起作用。知道怎么做吗?
它必须是网格,我无法改变它。
html,
body {
height: 100%;
width: 100%;
overflow: hidden;
}
body {
display: flex;
}
.container {
display: flex;
flex-direction: column;
flex: 1;
}
content {
flex: 1;
background-color: red;
}
header {
background-color: limegreen;
display: grid;
grid-template-columns: 0fr 1fr 0fr;
}
header div {
border: 1px solid orange;
}
.long {
text-overflow: ellipsis;
}
<div class="container">
<header>
<div>Left</div>
<div class="long">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
<div>Right</div>
</header>
<content>
</content>
</div>
【问题讨论】:
-
将此属性添加到 .long { white-space: nowrap;overflow:hidden;text-overflow:elipses;} 希望这里有效是参考链接css-tricks.com/snippets/css/truncate-string-with-ellipsis
-
@Michael_B 这对我来说似乎是独一无二的,不是重复的,OP 正在询问使用 CSS Grid 将其截断为单行,这是与链接副本中的多行非网格解决方案不同的野兽问题
-
@Lounge9,这并不是真正重要的问题。这是答案。而这个问题在副本中有完整的答案。 (因此,上面的注释指出:这个问题在这里已经有了答案)。