|
|
1
InSync
1 年前
首先,减去的裕度
.flex-col:last-child
来自其
flex-basis
以使其适合其父对象:
calc(50% - 0.5rem)
。然后,任意一组
white-space: pre-wrap
或使用
width: 0; min-width: 100%;
技巧:
.flex-row .flex-col:last-child {
flex-basis: calc(50% - 0.5rem);
margin-left: 0.5rem;
}
pre {
/* Either */
white-space: pre-wrap;
/* or */
width: 0;
min-width: 100%;
}
试试看:
.flex-row .flex-col:last-child {
flex-basis: calc(50% - 0.5rem);
margin-left: 0.5rem;
}
pre {
width: 0;
min-width: 100%;
}
/* Original styles */
* {
box-sizing: border-box;
}
.container {
background: #F5F5F5;
border: 1px solid #CCC;
margin: 0 auto;
padding: 0.5rem;
width: 500px;
}
.flex-row {
display: flex;
background: rgba(255, 0, 0, 0.1);
padding: 0.5rem 0;
}
.flex-col {
flex-basis: 50%;
flex-grow: 0;
flex-shrink: 0;
background: rgba(0, 255, 0, 0.1);
}
pre {
border: 1px solid red;
padding: 0.5rem;
overflow-y: scroll;
max-width: 100%;
}
<div class="container">
<p>Some text in a container</p>
<div class="flex-row">
<div class="flex-col">
<p>Some text in a column. Lorem ipsum dolor, sit amet consectetur adipisicing elit. Necessitatibus ea sint placeat deserunt, aut dolor et dolorum itaque, consequuntur minima quibusdam neque? Sequi eaque unde repudiandae, excepturi quibusdam maiores
incidunt.</p>
</div>
<div class="flex-col">
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Iste recusandae, repellendus ipsum accusantium rerum dolor fugiat, aperiam harum asperiores, vel debitis. Quidem modi sapiente enim. Ipsam saepe blanditiis ipsa id?</p>
</div>
</div>
</div>
<hr>
<div class="container">
<p>Some text in a container</p>
<div class="flex-row">
<div class="flex-col">
<p>Some text in a column. Lorem ipsum dolor, sit amet consectetur adipisicing elit. Necessitatibus ea sint placeat deserunt, aut dolor et dolorum itaque, consequuntur minima quibusdam neque? Sequi eaque unde repudiandae, excepturi quibusdam maiores
incidunt.</p>
</div>
<div class="flex-col">
<pre>Lorem, ipsum dolor sit amet consectetur adipisicing elit.
Iste recusandae, repellendus ipsum accusantium rerum dolor fugiat,
aperiam harum asperiores, vel debitis.
Quidem modi sapiente enim. Ipsam saepe blanditiis ipsa id?</pre>
</div>
</div>
</div>
或者,您可以使用
grid
随着
gap
,虽然没有得到广泛支持,但仍然存在了
about 6 years
:
.flex-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.5rem;
}
试试看:
.flex-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.5rem;
}
pre {
width: 0;
min-width: 100%;
}
/* Original styles */
* {
box-sizing: border-box;
}
.container {
background: #F5F5F5;
border: 1px solid #CCC;
margin: 0 auto;
padding: 0.5rem;
width: 500px;
}
.flex-row {
background: rgba(255, 0, 0, 0.1);
padding: 0.5rem 0;
}
.flex-col {
background: rgba(0, 255, 0, 0.1);
}
pre {
border: 1px solid red;
padding: 0.5rem;
overflow-y: scroll;
max-width: 100%;
}
<div class=“container”>
<p>容器中的某些文本</p>
<div class=“flex row”>
<div class=“flex col”>
<p>列中的某些文本。Lorem ipsum dolor,坐amet consectetur adipiscicing elit。必须在运行时、运行时和运行时进行必要的维护,以确保最低限度的维护?除主要昆虫外,其余均为昆虫科
令人难以置信</p>
</div>
<div class=“flex col”>
<p>Lorem,ipsum dolor坐amet consectetur adipislicing elit。Iste recasandae,reprindus ipsum accusantium rerum dolor fugiat,开胃酒harum asperiores,vel debtis。这是一个智慧的时代。我是谁</p>
</div>
</div>
</div>
<hr>
<div class=“container”>
<p>容器中的某些文本</p>
<div class=“flex row”>
<div class=“flex col”>
<p>列中的某些文本。Lorem ipsum dolor,坐amet consectetur adipiscicing elit。必须在运行时、运行时和运行时进行必要的维护,以确保最低限度的维护?除主要昆虫外,其余均为昆虫科
令人难以置信</p>
</div>
<div class=“flex col”>
<pre>Lorem,ipsum dolor坐amet consectetur adipislicing elit。
Iste recasandae,repellendus ipsum accusantium rerum dolor fugiat,
开胃酒有粗糙的味道,还有苦味。
这是一个智慧的时代。我是谁</pre>
</div>
</div>
</div>
|