I'm currently working on my first page where I want to use CSS grid display: grid
.
It works very well, but I come across a small problem with an element that I want float
classically - text floats around an image, a quote etc.
I simply gave an element a float: left
and to my surprise, the float
is completely ignored. The element remains as a full "grid-row-item".
Short code example:
main {
display: grid;
grid-template-columns: 5% 5% 1fr 5% 5%;
}
main > * {
grid-column: 3;
}
blockquote {
grid-column: 2 / -2;
}
blockquote.float-left {
grid-column: 3;
float: left;
}
For a larger example, I've created a Codepen.
Unfortunately, I have not found anything about this, so my questions are: Has anyone a solution for this? Have I overlooked something? Or maybe that's not possible yet?
Thank you in advance! :)
Codepen-Link:
https://codepen.io/anon/pen/GQWPWX
The float property still exists in CSS as it did when Internet Explorer was a young browser, and still works the same.
Grid and flexbox. The basic difference between CSS Grid Layout and CSS Flexbox Layout is that flexbox was designed for layout in one dimension - either a row or a column. Grid was designed for two-dimensional layout - rows, and columns at the same time.
There is actually one solution, use:
float: left; in grid works as => justify-self: start;
float: right; in grid works as => justify-self: end;
Floats are respected on grid containers, but they are completely ignored on grid items.
This behavior is defined in the CSS Grid spec in this section:
The problem has been discussed here, but has no solution yet:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With