如何在网格列中设置文本区域元素的样式?
How to style textarea-element in grid column?
我正在使用与 styledcomponents
的反应并让我的头绕过 css-网格,在对齐 textarea
时遇到问题,无法获得正确的高度(在下一行溢出)和宽度(必须与右侧的 'col3' 对齐):
const Wrapper = styled.div`
display:grid
grid-template-columns: 1fr 1fr 1fr 30px;
grid-template-rows:25% 25% auto;
justify-items: start;
border: solid 1px #000000
`
const ColumnSpan2 = styled.div`
grid-column: 2/4;
grid-row: row 2;
`;
组件如下所示:
<Wrapper>
<Column1>
<select>
<option>een</option>
<option>twee</option>
</select>
</Column1>
<Column2>
<input type="text" value="col2" />{' '}
</Column2>
<Column3>
<input type="text" value="col3" />{' '}
</Column3>
<Column4>todo iceon </Column4>
<ColumnSpan2>
{' '}
<textarea>Hello comments here</textarea>
</ColumnSpan2>
</Wrapper>
css:
body {
margin: 0 auto;
max-width: 60%;
}
textarea{
width: 200%;
height: 100%
}
如何获得 textarea
的正确样式(我尝试更改 grid-template-rows
道具但没有给出解决方案)
我创建了一个普通的 CSS 表示您的 React 代码 - 这里有一些提示:
justify-items: start
会将 内的内容对齐 网格项 - 考虑删除它(以及 width: 200%
等,我猜你是试图解决它保持 justify-items
)
现在将input
、select
和textarea
的宽度设置为填充它们的网格单元格使用width: 100%
grid-row: row 2
无效,因为您在 grid-template-rows
定义中没有 named grid-line
- 将其更改为 grid-row: 2
,
您没有为 网格容器定义高度 - 因此您可以将 grid-template-rows
更改为 grid-template-rows: auto auto
,
还要注意 grid-gap
和 padding
的用法,以调整 网格项之间的 空间 .
参见下面的演示:
body {
margin: 0 auto;
max-width: 60%;
}
textarea, input, select {
width: 100%; /* extend the width of the grid item */
box-sizing: border-box; /* including padding / border in width */
}
.wrapper {
display: grid;
grid-template-columns: 1fr 1fr 1fr 30px;
grid-template-rows: auto auto; /* changed */
border: solid 1px #000000;
grid-gap: 10px; /* grid gap to handle spaces between items if needed */
padding: 5px; /* space between wrapper and grid items */
}
.column1 {
grid-column: 1/2;
}
.column2 {
grid-column: 2/3;
}
.column3 {
grid-column: 3/4;
}
.column4 {
grid-column: 4/5;
}
.colspan2 {
grid-column: 2/4;
grid-row: 2; /* changed */
}
<div class="wrapper">
<div class="column1">
<select>
<option>een</option>
<option>twee</option>
</select>
</div>
<div class="column2">
<input type="text" value="col2" />
</div>
<div class="column3">
<input type="text" value="col3" />
</div>
<div class="column4">(i)</div>
<div class="colspan2">
<textarea>Hello comments here</textarea>
</div>
</div>
我正在使用与 styledcomponents
的反应并让我的头绕过 css-网格,在对齐 textarea
时遇到问题,无法获得正确的高度(在下一行溢出)和宽度(必须与右侧的 'col3' 对齐):
const Wrapper = styled.div`
display:grid
grid-template-columns: 1fr 1fr 1fr 30px;
grid-template-rows:25% 25% auto;
justify-items: start;
border: solid 1px #000000
`
const ColumnSpan2 = styled.div`
grid-column: 2/4;
grid-row: row 2;
`;
组件如下所示:
<Wrapper>
<Column1>
<select>
<option>een</option>
<option>twee</option>
</select>
</Column1>
<Column2>
<input type="text" value="col2" />{' '}
</Column2>
<Column3>
<input type="text" value="col3" />{' '}
</Column3>
<Column4>todo iceon </Column4>
<ColumnSpan2>
{' '}
<textarea>Hello comments here</textarea>
</ColumnSpan2>
</Wrapper>
css:
body {
margin: 0 auto;
max-width: 60%;
}
textarea{
width: 200%;
height: 100%
}
如何获得 textarea
的正确样式(我尝试更改 grid-template-rows
道具但没有给出解决方案)
我创建了一个普通的 CSS 表示您的 React 代码 - 这里有一些提示:
justify-items: start
会将 内的内容对齐 网格项 - 考虑删除它(以及width: 200%
等,我猜你是试图解决它保持justify-items
)现在将
input
、select
和textarea
的宽度设置为填充它们的网格单元格使用width: 100%
grid-row: row 2
无效,因为您在grid-template-rows
定义中没有named grid-line
- 将其更改为grid-row: 2
,您没有为 网格容器定义高度 - 因此您可以将
grid-template-rows
更改为grid-template-rows: auto auto
,还要注意
grid-gap
和padding
的用法,以调整 网格项之间的 空间 .
参见下面的演示:
body {
margin: 0 auto;
max-width: 60%;
}
textarea, input, select {
width: 100%; /* extend the width of the grid item */
box-sizing: border-box; /* including padding / border in width */
}
.wrapper {
display: grid;
grid-template-columns: 1fr 1fr 1fr 30px;
grid-template-rows: auto auto; /* changed */
border: solid 1px #000000;
grid-gap: 10px; /* grid gap to handle spaces between items if needed */
padding: 5px; /* space between wrapper and grid items */
}
.column1 {
grid-column: 1/2;
}
.column2 {
grid-column: 2/3;
}
.column3 {
grid-column: 3/4;
}
.column4 {
grid-column: 4/5;
}
.colspan2 {
grid-column: 2/4;
grid-row: 2; /* changed */
}
<div class="wrapper">
<div class="column1">
<select>
<option>een</option>
<option>twee</option>
</select>
</div>
<div class="column2">
<input type="text" value="col2" />
</div>
<div class="column3">
<input type="text" value="col3" />
</div>
<div class="column4">(i)</div>
<div class="colspan2">
<textarea>Hello comments here</textarea>
</div>
</div>