gpt4 book ai didi

html - 表单对齐折叠成单行

转载 作者:行者123 更新时间:2023-11-28 14:20:01 27 4
gpt4 key购买 nike

我将父元素设置为 newTableForm,将 labelColumnmainFormColumn 作为子元素 - 但使用当前的 CSS,所有内容都折叠成一行:

.newTableForm {
display: grid;
grid-template-columns: 1fr 3fr;
grid-template-rows: 30px 30px 30px 40px;
grid-gap: 10px;
grid-template-areas: "... main" "labels main" "labels main" "... main";
border: 2px dashed deeppink;
}

.labelColumn {
grid-area: labels;
}

.mainFormColumn {
grid-area: main;
}
<form method='post' action="/admin-post.php" class="newTableForm">
<h4 class="mainFormColumn">
Add a new price compare table
</h4>
<label for="store" class="labelColumn">Store</label>
<input type="text" name="store" placeholder="" class="mainFormColumn"/>
<label for="product-page" class="labelColumn">Product Page Link</label>
<input type="text" name="product-page" placeholder="Copy address here" class="mainFormColumn" />
<button class="mainFormColumn">Save new price compare table</button>
</form>

有没有办法取消这里的单列堆叠行为?如果不是带有...(标签部分上方和下方)的空白部分,我将完全删除模板区域

最佳答案

同样,您可以将 grid-template-areas 作为多个网格区域重叠 - 您可以为此使用伪元素:

  • 使用 grid-column: 1mainFormColumnlabelColumn 放入第一列 第二列使用grid-column: 2

  • after 元素将成为最后一行中的第一列,使用grid-row: -2grid-column: 1

  • before 将是第一行中的第一列,使用grid-column: 1

请看下面的演示:

.newTableForm {
display: grid;
grid-template-columns: 1fr 3fr;
grid-template-rows: 30px 30px 30px 40px;
grid-gap: 10px;
border: 2px dashed deeppink;
}

.labelColumn {
grid-column: 1;
}

.mainFormColumn {
grid-column: 2;
}
.newTableForm:after, .newTableForm:before {
content: '';
display: block;
grid-column: 1;
}

.newTableForm:after {
grid-row: -2;
}
<form method='post' action="/admin-post.php" class="newTableForm">
<h4 class="mainFormColumn">
Add a new price compare table
</h4>
<label for="store" class="labelColumn">Store</label>
<input type="text" name="store" placeholder="" class="mainFormColumn"/>
<label for="product-page" class="labelColumn">Product Page Link</label>
<input type="text" name="product-page" placeholder="Copy address here" class="mainFormColumn" />

<button class="mainFormColumn">Save new price compare table</button>
</form>

关于html - 表单对齐折叠成单行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55325488/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com