<div class="template-form__list-wrapper--row">
<%-- company information --%>
<div class="template-form__list-item">
<div class="template-form__item-label template-form__item-label">Company</div>
</div>
<%-- person in charge --%>
<div class="template-form__list-item">
<div class="template-form__item-label template-form__item-label">PersonInCharge</div>
<input form="formCasePost" name="CasePostFormBean.contractorPersonnelName">
</div>
<%-- department --%>
<div class="template-form__list-item">
<div class="template-form__item-label">Department</div>
<input form="formCasePost" name="CasePostFormBean.contractorDepartmentName">
</div>
<div class = "case-post__list-company">default</div>
<div class = "case-post__list-company">Add new comapny</div>
</div>CSS
.template-form__list-wrapper--row {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
.template-form__list-item {
display: grid;
grid-template-columns: 10rem 1fr;
gap: 0.75rem;
align-items: center;
height: 100%;
}
.template-form__item-label {
display: flex;
justify-content: center;
align-items: center;
gap: 0.25rem;
height: 100%;
width: 10rem;
padding: 0.25rem 0;
background-color: var(--main-color--2);
border: 1px solid var(--border-color--1);
}
.case-post__list-company {
display: flex;
justify-content: center;
align-items: center;
padding: 0.25rem 0.5rem;
width: 5rem;
color: var(--main-color--1);
background-color: var(--button-color--1);
border: 1px solid var(--main-color--1);
border-radius: 0.25rem;
box-shadow: 0 3px 3px var(--border-color--3);
cursor: pointer;
}现在,这个内容显示如下

但是我想要的结果如下

在template-form__list-item中编辑网格布局正确吗?如果有人有意见,请告诉我。
谢谢
发布于 2022-11-11 05:07:28
问题
flex和grid属性的使用太多了。我对你的代码做了一点修正,包括标记和样式。(它的行为与你想要的风格完全一样,希望它能帮上忙!)
.template-form__list-wrapper--row {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
.template-form__list-item {
display: flex;
gap: 1rem;
align-items: center;
height: 100%;
}
.flex-wrap {
display: flex;
}
.input-wrapper {
display: flex;
flex-direction: column;
justify-content: center;
}
.template-form__item-label {
display: flex;
justify-content: center;
gap: 1rem;
height: 100%;
padding: 0.25rem 0;
background-color: var(--main-color--2);
border: 1px solid var(--border-color--1);
}
.case-post__list-company {
margin-top: 1rem;
margin-right: 0.5rem;
padding: 0.5rem;
border: 1px solid gray;
}<div class="template-form__list-wrapper--row">
<div class="template-form__list-item">
<div class="template-form__item-label template-form__item-label">
Company
<div class="input-wrapper">
<input form="formCasePost" name="CasePostFormBean.contractorPersonnelName" />
<div class="flex-wrap">
<div class="case-post__list-company">default</div>
<div class="case-post__list-company">Add new comapny</div>
</div>
</div>
</div>
</div>
<div class="template-form__list-item">
<div class="template-form__item-label template-form__item-label">
PersonInCharge
</div>
<input form="formCasePost" name="CasePostFormBean.contractorPersonnelName" />
</div>
<div class="template-form__list-item">
<div class="template-form__item-label">Department</div>
<input form="formCasePost" name="CasePostFormBean.contractorDepartmentName" />
</div>
</div>
https://stackoverflow.com/questions/74397495
复制相似问题