Understanding Grid
Here is the playground: https://jsfiddle.net/4L7v8jhx/1/
Edit fiddle - JSFiddle - Code Playground
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
22 Replies
ah, it goes wrong with the pseudoselector. It is a bit tricky, put a pseudoselector works on the element itself, not childs. What you are doing with
.container:first-child
is looking for a .container that IS the first child of something else.
what you need is .container > div:first-child
so, the div that IS the first-child within a parentOhhh okay
Thanks a bunch!
So now, I just repeat with the rest of the div's? So the next one would look like:
And so on...
yes that is an option. but instead of defining the start and end, you could also just use
span {number of cells}
the start position is the first available spot, and it spans over that number
example:
Aha, I see
Yes, that seems more efficient since it's much less code
and if you want it even more reduced, you could even use css variables
Oh okay, great! Will attempt that
Thanks! @MarkBoots 🙂
so here the span value is set inline as a variable, the div will get that value for the grid-column
you're welcome. Good luck
Grid is fun!
Thanks again! I agree!
@MarkBoots I appreciate your help, I just got 1 more question. If I didn't want to have any inline styles and have everything in my CSS file instead, how would I manage that?
then your option with nth-child(n) and span {number} should work
I use SASS, so perhaps still use variables?
Ah okay, thanks!
instead of nth-child i'd give my elements a class named after the amount of spans and then style those classes with the span custom prop from earlier
no inline styles that way but same flexibility
That's smart too, I'll try that out, thanks!
yea, thats is an option too.
(but if then, why not use custom props. then you don't have to define those classes)
I hope it's not a dumb q, but what's a custom prop?
css variable
a css variable
Ah okay
hopefully soon we can use attributes to calculate with (they are working on it). that would make it really great. you could do something like
<div cell-span="3">
That's cool yeah
sounds interesting
now it reads attribute as a string. so its not possible. but we'll be able to define the type of the value (in this case a number)
ohw, btw. you said scss
you can use this loop. it will generate classes
span-1
to span-12
ye, seems like the best solution, but i was too lazy to type all of that on my phone lol 😬