-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSSGrid.txt
More file actions
34 lines (32 loc) · 3.95 KB
/
CSSGrid.txt
File metadata and controls
34 lines (32 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
grid-template-columns:Simply creating a grid element doesn't get you very far. You need to define the structure of the grid as well. To add some columns to the grid.
grid-template-rows: similar to coloumn.
You can use absolute and relative units like px and em in CSS Grid to define the size of rows and columns. You can use these as well:
fr: sets the column or row to a fraction of the available space,
auto: sets the column or row to the width or height of its content automatically,
%: adjusts the column or row to the percent width of its container.
grid-column-gap:So far in the grids you have created, the columns have all been tight up against each other. Sometimes you want a gap in between the columns.
grid-row-gap:similar to column-gap.
grid-gap is a shorthand property for grid-row-gap and grid-column-gap from the previous two challenges that's more convenient to use. If grid-gap has one value, it will create a gap between all rows and columns. However, if there are two values, it will use the first one to set the gap between the rows and the second value for the columns.
Use grid-gap to introduce a 10px gap between the rows and 20px gap between the columns.
grid-column:
grid-row:
justify-self:In CSS Grid, the content of each item is located in a box which is referred to as a cell. You can align the content's position within its cell horizontally using the justify-self property on a grid item. By default, this property has a value of stretch, which will make the content fill the whole width of the cell. This CSS Grid property accepts other values as well:
start: aligns the content at the left of the cell,
center: aligns the content in the center of the cell,
end: aligns the content at the right of the cell.
align-self:Just as you can align an item horizontally, there's a way to align an item vertically as well. To do this, you use the align-self property on an item. This property accepts all of the same values as justify-self from the last challenge.
CSS Grid: Align All Items Horizontally using justify-items.
Sometimes you want all the items in your CSS Grid to share the same alignment. You can use the previously learned properties and align them individually, or you can align them all at once horizontally by using justify-items on your grid container. This property can accept all the same values you learned about in the previous two challenges, the difference being that it will move all the items in our grid to the desired alignment.
align-items:Using the align-items property on a grid container will set the vertical alignment for all the items in our grid.
grid-template-areas:You can group cells of your grid together into an area and give the area a custom name. Do this by using grid-template-areas on the container like this:
grid-template-areas:
"header header header"
"advert content content"
"footer footer footer";
grid-area:After creating an area's template for your grid container, as shown in the previous challenge, you can place an item in your custom area by referencing the name you gave it. To do this, you use the grid-area property on an item like this:
.item1 {
grid-area: header;
}
Minmax:There's another built-in function to use with grid-template-columns and grid-template-rows called minmax. It's used to limit the size of items when the grid container changes size. To do this you need to specify the acceptable size range for your item.
auto-fill:The repeat function comes with an option called auto-fill. This allows you to automatically insert as many rows or columns of your desired size as possible depending on the size of the container. You can create flexible layouts when combining auto-fill with minmax.
auto-fit: it works almost identically to auto-fill. The only difference is that when the container's size exceeds the size of all the items combined, auto-fill keeps inserting empty rows or columns and pushes your items to the side, while auto-fit collapses those empty rows or columns and stretches your items to fit the size of the container.