I have a few questions in the context of CSS grid with regard to <input> elements.
- Why does the label's and input's size match the grid's row height and fills it in?
- Why are the label and input elements displayed as
blockin CSS grid but as inline elements in a simple div? - Why is my attempt at overriding their display to be
inlineignored by the browser?
Finally, there's an implicit "how can I fix this" question here.
Here is an example:
.wrapper {
background-color: purple;
display: grid;
grid-template-columns: 1fr 4rem 4rem 1fr;
}
.wrapper > label {
display: inline;
grid-column: 2;
background-color:green;
}
.wrapper > input[type=checkbox] {
grid-column: 3;
border: 1px solid red;
background-color: gray;
}
.wrapper > input[type=text] {
grid-column: 4;
outline: 2px solid yellow;
}
.simple {
width: 50px;
height: 100px;
background-color: blue;
}
.simple > label {
height: 50px;
}
.wrapper2 {
background-color: gray;
display: grid;
grid-template-rows: 100px;
grid-auto-rows: 100px;
grid-template-columns: 1fr 8rem 8rem 1fr;
}
.wrapper2 > label {
grid-column: 2;
display: inline;
background-color:green;
}
.wrapper2 > input[type=checkbox] {
grid-column: 3;
background-color:yellow;
border: 1px solid gray;
}
.wrapper2 > input[type=text] {
grid-column: 4;
outline: 2px solid yellow;
border: 1px solid gray;
}
<div class="wrapper">
<label for="cb">Long Label</label>
<input id="cb" type="checkbox">
<input id="t3" type="text">
</div>
<div class="simple">
<label for="cb2">Long Label</label>
<input id="cb2" type="checkbox">
<input id="t2" type="text">
</div>
<div class="wrapper2">
<label for="cb3">Long Label</label>
<input id="cb3" type="checkbox">
<input id="t3" type="text">
</div>