我想创建以下内容:
Left Text - - - - - - Center Text - - - - - - Right Text
其中 - - - - - 是一条1px的虚线,位于文本高度的中间。
带有space-between
的Flexbox容器。虚线是1px高度跨度的边界。确保文本跨度不随flex: 0 0 auto;
增长
.container {
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
}
.container .text {
flex: 0 0 auto;
}
.container .dashed {
display: block;
width: 50%;
height: 1px;
border-top: 1px dashed #000;
margin: 0 5px;
box-sizing: border-box;
}
<div class="container">
<span class="text">Left Text</span>
<span class="dashed"></span>
<span class="text">Center Text</span>
<span class="dashed"></span>
<span class="text">Right Text</span>
</div>
我会这样做:https://jsfiddle.net/s59rzh4b/
<div class="outer">
<div class="center">
<span class="middle">More text</span>
</div>
<span class="left">Some text</span>
<span class="right">Even more...</span>
</div>
.outer {
position: relative;
width: 100%;
}
.outer > * {
position: absolute;
background: white;
padding: 0 5px;
top: 0;
}
.left {
left: 0;
}
.center {
text-align: center;
width: 100%;
height: 8px;
border-style: solid;
border-color: black;
border-width: 0 0 2px 0;
}
.middle {
background: white;
padding: 0 5px;
}
.right {
right: 0;
}
html, body, .grid-container { height: 100%; margin: 0; }
.grid-container *:after {
position: absolute;
top: 0;
left: 0;
}
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr;
grid-template-areas: "t1 t2 t3" ". . ." ". . .";
txt-align: center;
}
.t1 { grid-area: t1; }
.t2 { grid-area: t2; }
.t3 { grid-area: t3; }
<div class="grid-container">
<div class="t1">sfsfds -----------------------</div>
<div class="t2">dsfsdf -------------------</div>
<div class="t3">dsfdsf -----------------------</div>
</div>
这个??