First steps trying to understand CSS Grid.
You will see that as you widen the display this switches between text "Client code" being displayed on one line, ... a line break occurring ... one line ... line break ... one line ... etc.
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
border: 0.5px solid Magenta;
}
.flex-display {
display : flex;
border: 0.5px solid Green;
}
.dbForm *{
font-size: x-small;
}
.dbForm-nonTable {
margin: 2px;
padding: 2px;
border: 0.5px solid #000000;
overflow: auto;
background-color: #ffec80; /* light gold */
min-height: 10px;
min-width: 30px;
}
.dbForm-label {
margin: 2px;
padding: 2px;
overflow: auto;
min-height: 10px;
}
<body>
<div class="dbForm" dbase-source="invoices" >
<div class="grid-container">
<div class="flex-display">
<div class="dbForm-label">Date:</div>
<div class="dbForm-nonTable">bumble doo</div>
</div>
<div class="flex-display">
<div class="dbForm-label">Client code:</div>
<div class="dbForm-nonTable">Dodo</div>
</div>
<div class="flex-display">
<div class="dbForm-label">Notes:</div>
<div class="dbForm-nonTable">Nabble</div>
</div>
</div>
</div>
</body>
There's also a JSFiddle here.
In each case, the idea is that there is a "label" and a "dbase value" box, and I want these always to stay together on the same line. Hence the use of display : flex
to keep these together.
I was puzzled by this switching phenomenon. Then I presumed that what's happening is that because I have used minmax(100px, 1fr)
, that what's effectively happening as the grid gets wider is that it is inserting "imaginary" DIVs (each occupying "1fr") to the right of the 3 "real" DIVs, when the width allows this to happen. But one effect of this can then be that, in order to fit OK, the text "Client code" has to introduce a line break.
What I actually want is for the 3 "real" DIVs to be the only ones ... and either to expand to greater and greater widths as the grid gets much wider, or just stay at the width they reach when all 3 are on one row, and there's no line breaking. I'd like it if the line breaking only occurred when the viewport was really narrow and there was no other option - situations which occur currently at one point with 2 cols and at another with 3.
I basically would like to stop the insertion of "imaginary" DIVs.
Can anyone give any insight how to achieve that?
It occurred to me that I might just put a non-breaking space
between "Client" and "code". This didn't strike me as very elegant, but I tried it. With this particular setup (font, widths, etc.), this then causes an alternation of a different kind as you widen: one-line ... horizontal scrollbar ... one-line ... horizontal scrollbar...
PS I notice that if I change to minmax(150px, 1fr)
"Client code" never gets a line break... with the text present in the dbase box ("Dodo"). But equally, if the text in the dbase box is made longer "Client code" starts line-breaking again. What I'd like is for the dbase box to allow the text inside it to be allowed to line-break but (except for the 2 situations mentioned above, one at 2 cols the other at 3) not the label.