【发布时间】:2018-11-06 10:40:39
【问题描述】:
我在 100% 宽度的 flex 行中有两个文本字段。一个位于左侧,另一个位于右侧。当容器(窗口)从右侧调整大小(更小)时,我希望右侧的文本重叠/覆盖左侧的文本。
解决方案不得使用绝对定位。左边的文本有一个左边距,右边的文本必须停止。文本容器故意设置为 100% 宽度的行。
Fiddle 不是布局和调整大小测试的最佳平台,但 https://jsfiddle.net/Lcjcyp4g/6/
为了完整起见,下面的 flex 代码中注释掉了 position:abs 解决方案。请忽略 resize-right 上的行为——我们唯一关注的是 resize-left 上的文本重叠。
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="container">
<div class="container--text">
<div class="left">Left Text</div>
<!-- <div class="container--right"> -->
<div class="right">Right Text</div>
<!-- </div> -->
</div>
</div>
</body>
</html>
html, body {
height: 100vh;
width:100%;
background-color: #D7CCC8;
overflow: hidden;
margin: 0;
padding: 0;
}
.container {
min-width:100%;
width:100%;
margin-left:20px;
height: 14px;
max-height:14px;
}
.container--text {
height: 14px;
max-height:14px;
width:100%;
display: flex;
flex-flow: row nowrap;
padding: 10px 0;
}
.left {
white-space: nowrap;
color: #000000;
font-size: 14px;
font-weight: bold;
text-overflow: ellipsis;
flex-shrink:1;
}
/* This is not a viable soln because there is no boundary left for the pos:absolute element without JS*/
.container--right {
/*height: 14px;
background-color: #D7CCC8;
position:absolute;
right:0;
*/
}
.right {
white-space: nowrap;
justify-self:flex-end;
margin-left:auto;
margin-right:20px;
background-color:#BCAAA4;
color: #616161;
font-size: 12px;
}
【问题讨论】:
-
??这是你尝试做的吗jsfiddle.net/Lcjcyp4g/4 .
-
是否希望右侧的文本在缩放时超出顶部?还是左边的文字消失?
标签: html css flexbox css-position