【发布时间】:2020-07-17 17:23:41
【问题描述】:
我有一个带边的主容器。旁边有一个固定的宽度,我正在使用 CSS Grid 来绘制这个容器。在主容器内,有一系列包含动态数据的列,这些列会根据需要自动流动、对齐以及将数据从一列转移到另一列。此列设置使用 CSS 多列,但列的宽度会根据用户浏览器的屏幕大小而改变。我想找到一个 CSS 解决方案,将这些列保持在设定的宽度。有没有办法自动扩展最后绘制的列?或者有没有办法阻止动态多列计数扩展?我试过align-items:start,但没有看到效果。有没有办法通过容器将列保持在设定的宽度?
@charset "UTF-8";
/* https://stackoverflow.com/questions/7785374/how-to-prevent-column-break-within-an-element */
html, body {
padding: 0;
margin: 0;
}
section {
padding: 3px;
}
input {
width: 100%;
box-sizing: border-box;
}
label {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: block;
font-family: "Miriam Libre";
font-size: 10px;
color: #213C3A;
}
.Cols {
margin: 0;
padding: 0;
columns: 40ch;
column-count: auto;
column-fill: auto;
column-rule: 1px dotted #3DB199;
height: 100vh;
/* ↓ columns defined by width */
overflow: auto;
}
li {
width: 100%;
display: inline-block;
padding: 3px;
border-bottom: 1px solid #D36B66;
}
.G {
display: grid;
}
.G-wAside {
grid-template-columns: 1fr minmax(0, 10vw) 10vw;
gap: 1vw;
}
.G-23 {
grid-template-columns: 66.66% 33.33%;
}
.HVpZ {
height: 100%;
}
.WVpZ {
width: 100%;
}
.filler {
background: #CCE0E2;
}
.fieldset {
margin: 5px 3px;
}
.fieldset > * {
margin: 1px 0;
}
.fieldset label {
margin-right: 3px;
}
.placeholder-uploader {
height: 320px;
width: 100%;
background: #FAF9E9;
}
.placeholder-grid {
width: 640px;
height: 230px;
background: #FAF9E9;
position: absolute;
}
.col-container {
overflow: hidden;
position: relative;
height: 100px;
grid-row-start: span 2;
}
<main class="G HVpZ WVpZ G-wAside">
<section>
<ul class="Cols">
<li>
<div class="fieldset">
<label>New List Is Just Long</label>
<input type="text"></input>
</div>
<div class="fieldset">
<label>Label Is Just Long</label>
<input type="text"></input>
</div>
<div class="fieldset">
<label>Label Is Just Long</label>
<input type="text"></input>
</div>
<div class="fieldset">
<label>Label Is Just Long</label>
<input type="text"></input>
</div>
<div class="col-container">
<div class="placeholder-grid"></div>
</div>
<div class="G G-23">
<div class="fieldset">
<label>Grid Label DIV Name</label>
<input type="text"></input>
</div>
<div class="fieldset">
<label>Label Is Just Longest Of All</label>
<input type="text"></input>
</div>
</div>
<div class="fieldset">
<label>Label Is Just Long</label>
<input type="text"></input>
</div>
</li>
<li>
<div class="col-container">
<div class="placeholder-grid"></div>
</div>
</li>
<li>
<p>Praesent vestibulum semper erat ut varius. Donec sed erat ac odio ultricies bibendum et sit amet lectus. In placerat consequat mi, sed commodo mauris ornare non. Integer nibh leo, dignissim in purus at, pretium porta nibh. Nulla vestibulum imperdiet
sollicitudin. Morbi euismod justo metus, quis imperdiet nunc eleifend ultrices. Donec nec maximus lacus. Aenean tincidunt mattis nisi, eget molestie dolor iaculis vel. Praesent faucibus risus vel arcu tincidunt, id varius orci bibendum. Duis
posuere est in diam luctus ultrices id in sapien. Fusce bibendum pharetra velit, sit amet commodo diam pharetra ac.</p>
</li>
</ul>
</section>
<section class="filler">← How to auto-fill this space to keep css multi columns in previous grid item to set width of 40ch? →</section>
<section class="bg">Aside</section>
</main>
【问题讨论】:
-
我无法理解您的问题。我有一个想法,但不确定我的理解是否正确。因此,您有一个带有输入字段的部分,这些字段会根据视口的大小改变大小。您希望此部分具有 固定 宽度。此外,您希望
aside部分填补空白。对吗?
标签: css css-grid fixed-width css-multicolumn-layout