我想才达到的布局是这样的:如何在新行中显示文本,即使它可以放在单行中?
所以字幕总是在第二行至少,即使它可能适合在第一行标题旁边。如果标题很长并且分成两行或更多行,则副标题应该跟随标题而不会打破新行。
这是我做的,到目前为止,但这种解决方案并不完美:
div.data {
background:white;
position:relative;
min-height: 2em;
float:left;
max-width:150px;
margin: 50px;
}
.title {
position:relative;
overflow:hidden;
background: white;
z-index: 10;
}
.title span {
position:relative;
}
.title span span {
position:absolute;
right:0px;
opacity:1;
top: 18px;
display: block;
transform: translateX(100%);
padding-left: 5px;
color: red;
}
span.subtitle {
position:absolute;
bottom:0;
left:0;
z-index: 5;
display:block;
color: red;
}
<div class="data">
<div class="title"><span>title <span>subtitle</span></span></div>
<span class="subtitle">subtitle</span>
</div>
<div class="data">
<div class="title"><span>reaallllyyyy loooooong title <span>subtitle</span></span></div>
<span class="subtitle">subtitle</span>
</div>
很抱歉的问题的标题,那是最好的我能想出。
只是评论,如果文本被包裹CSS无法察觉。你可以使用JavaScript/jQuery? – tech2017