我想创建以下内容:
Left Text - - - - - - Center Text - - - - - - Right Text
其中-----是1px的虚线,位于文本高度的中间。
答案 0 :(得分:2)
带有space-between
的Flexbox容器。虚线是1像素高度跨度上的边框。确保文本范围不会随着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>
答案 1 :(得分:0)
我会做这样的事情: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;
}
答案 2 :(得分:-1)
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>
这个?