css-grid

How to calc() the number of rows in a grid template?

时间秒杀一切 提交于 2019-12-01 17:57:15
I'd like to calculate the number of rows in a grid template using calc() , but trying to get the repeat count with division isn't working: .grid { display: grid; grid-gap: 10px; grid-template-columns: 1fr; margin-bottom: 10px; background: rgba(0, 0, 0, 0.2); } .grid>div { background: tomato; width: 20px; text-align: center; margin: auto; } .grid.no-calc { grid-template-rows: repeat(3, 30px); } .grid.addition { grid-template-rows: repeat(calc(1 + 2), 30px); } .grid.subtraction { grid-template-rows: repeat(calc(4 - 1), 30px); } .grid.multiplication { grid-template-rows: repeat(calc(3 * 1), 30px)

Horizontal border across entire row of CSS GRID

余生长醉 提交于 2019-12-01 17:28:52
I need to use a grid layout but also need a horizontal line separating each row. The only thing I've been able to find is applying a border to each cell, but this only works if there are enough cells to fill each row. .wrapper { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 100px); } .box { border-bottom: 2px solid #ffa94d; padding: 1em; } <div class="wrapper"> <div class="box">One</div> <div class="box">Two</div> <div class="box">Three</div> <div class="box">Four</div> </div> Is there a way to fix the above so that the entire row has a border? Add a grid

Wrap CSS grid with auto placement

三世轮回 提交于 2019-12-01 16:37:26
问题 I'm trying to build a grid that contains card-like items. The cells of each type (headline, image, text, button, ...) should have equal height in each row, determined by the content of the largest cell, as in the code snippet below. Now I'm trying to limit the number of columns, and let the cards wrap, as if I used flex-wrap: wrap; in a flexbox-based solution. The number of columns should be determined via media query. Is this possible without using the not-yet-supported subgrids?

Why does a grid item with a grid-area name, but not defined in grid-template-areas, create an additional column?

余生颓废 提交于 2019-12-01 14:05:39
问题 I've created a simple CSS Grid, I decided to not specify grid-template , grid-template-columns , grid-template-rows properties. Instead, I started with grid-template-areas , and assigned area names to the grid-items via grid-area property. After that, I was interested in what would happen if I remove grid-item from grid-template-areas . The result was kind of strange. The removed grid-item was placed on the right and separated by additional column. The problem: Why did this happen? Is this

CSS only solution to set “same height” row sections on a responsive grid

若如初见. 提交于 2019-12-01 11:34:06
Wanted : a CSS only solution to enable equal height grid "sections" on a per row basis, that is also responsive. This diagram hopefully explains the requirement better than the words in this post will: The "item grid" should be responsive - in that it can show a different number of cards per row based on viewport width. And within a given row, the equivalent sections should have the same height on a "per row" basis. In the below HTML & CSS - the item cards are split in to the rows that we need (at the two example break points desktop & mobile) but the content section heights are variable (yuck

Chrome / Firefox percentage height differences in CSS Grid

五迷三道 提交于 2019-12-01 10:47:10
Please note, the following problem can be solved by using fr units instead of % and auto, but I am looking for an explanation as to why the problem occurs in the first place. In my code below, Firefox : Does not obey the values for grid-template-rows . Applies an equal height to each row but the grid items do not overflow the container. Chrome : Seems to obey the grid-template-rows property but the grid items overflow the container. Initially I thought the issue was with % but it is an allowable unit for the row. I swapped out the auto value for 10% but that created its own problem. I've

CSS only solution to set “same height” row sections on a responsive grid

£可爱£侵袭症+ 提交于 2019-12-01 10:18:52
问题 Wanted : a CSS only solution to enable equal height grid "sections" on a per row basis, that is also responsive. This diagram hopefully explains the requirement better than the words in this post will: The "item grid" should be responsive - in that it can show a different number of cards per row based on viewport width. And within a given row, the equivalent sections should have the same height on a "per row" basis. In the below HTML & CSS - the item cards are split in to the rows that we

Center a flex item in a row when there are a different number of items on each side

£可爱£侵袭症+ 提交于 2019-12-01 09:26:42
How do I achieve this layout drawn on the picture? E.g. 3 items on left side, one centered, 2 on the right. the ul is the orangish color and the black boxes are the items ul { display: flex; width: 100%; } <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <li>Item 4</li> <li>Item 5</li> <li>Item 6</li> </ul> Flexbox Use 7 items. One in the center. Each side has 3. Hide one on the right with visibility: hidden . If you don't want to add a fake item in the DOM, then use a pseudo-element instead, also with visibility: hidden . More details here: Center and right align flexbox elements How can

Maintain ratio between column in CSS grid. How grid-column is calculated?

点点圈 提交于 2019-12-01 09:13:55
I want my grid to maintain a certain ratio, but a long sentence increases the width of the grid it belongs to. body { display: grid; } main { grid-column: 1 / 8; border: 2px solid black; } aside { grid-column: 8 / 13; border: 2px solid black; } <main> <p>Mauris neque quam, fermentum ut nisl vitae, convallis maximus nisl. Sed mattis nunc id lorem euismod placerat. Vivamus porttitor magna enim, ac accumsan tortor cursus at. Phasellus sed ultricies mi non congue ullam corper. Praesent tincidunt sed tellus ut rutrum. Sed vitae justo condimentum, porta lectus vitae, ultricies congue gravida diam

How to create a CSS Grid Layout box that spans 2 columns and 2 rows?

半城伤御伤魂 提交于 2019-12-01 09:07:11
I've created a grid layout following the newest CSS Grid spec, but am not completely familiar with it yet. I'm trying to create the following layout without having to define grid areas for each grid child. codepen body { max-width: 1024px; margin: 10px auto; } .grid { display: grid; grid-gap: 10px; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; grid-template-areas: "a a b" "a a c" "d e f"; } .grid__thing { background-color: rebeccapurple; } .a { grid-area: a; } .b { grid-area: b; } .c { grid-area: c; } .d { grid-area: d; } .e { grid-area: e; } .f { grid-area: f; } img {