【发布时间】:2017-07-01 16:15:43
【问题描述】:
我正在尝试根据屏幕的中心使标题居中,而它的容器不会占用屏幕宽度的 100%。
我还需要截断文本并且不想在右侧留下填充。
This is what I've got so far - JSFiddle。您可以看到黄色 div 中的文本与下面的文本没有对齐。如果我在黄色 div 中添加 padding-right,则在调整大小时,文本不会占用黄色 div 的 100%。有什么建议?
HTML
<div class="cont">
<div class="left-h">
place holder
</div>
<div class="middle-h">
my very long long title goes here
</div>
</div>
<div class="real-center">
my very long long title goes here
</div>
CSS
.cont{
width: 100%;
border: 1px solid black;
display: flex;
text-align: center;
}
.left-h{
flex-basis: 150px;
background-color: #e5e5e5;
}
.middle-h{
background-color: yellow;
flex-grow: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.real-center{
width: 100%;
text-align:center;
}
【问题讨论】:
-
哪一个是真题?
-
真正的地方是下面那个——我添加它只是作为视觉参考,但标题应该只出现在黄色的div中
-
是你需要的吗?:jsfiddle.net/banzay52/pzbk869h