css-grid

minmax fails (invalid property value)

烂漫一生 提交于 2019-11-28 04:32:20
问题 Chrome gives an invalid property value and doesn't respect the CSS: grid-template-columns: repeat(auto-fill, minmax(auto, 1fr)); It also fails when auto is replaced with min-content and max-content . It works as expected when auto is replaced by a fixed value e.g. grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); This is surprising because both repeat and minmax support the keywords. The html is simple <div class='wrapper> <div>...</div> <div>...</div> </div> and css .wrapper {

CSS Grid vertical columns with infinite rows

五迷三道 提交于 2019-11-28 04:02:35
问题 I have a list of items of unknown length (from a CMS). I want to display them in 2 vertical columns reading down. e.g. 1 4 2 5 3 6 etc... I am trying to achieve this with CSS grid, however, it doesn't seem possible unless you set the number of rows up front. I have tried grid-auto-flow: column as per https://gridbyexample.com/examples/example18/ but this just adds additional columns when it gets to the end. I feel like this should be possible with grid, but I can't find a way. Anyone have any

Why doesn't min-content work with auto-fill or auto-fit?

你离开我真会死。 提交于 2019-11-28 03:16:55
问题 Basically, I do not understand why this works: .grid { display: grid; grid-template-columns: repeat(4, min-content); } But this doesn't work: .grid { display: grid; grid-template-columns: repeat(auto-fill, min-content); } I really wish to make the latter functionality possible. Are there other ways to make it work? 回答1: The second rule doesn't work because min-content is an intrinsic sizing function . § 7.2.2.1. Syntax of repeat() Automatic repetitions ( auto-fill or auto-fit ) cannot be

Masonry layout with css grid

a 夏天 提交于 2019-11-28 02:51:06
问题 I'm trying to create masonry layout using css grid layout . All items in grid have variable heights. And I don't know what items will be. So I can't define grid-row for each item. Is it possible to start each new item right after end of previous in column? Code I'm trying: .wrapper { display: grid; grid-template-columns: repeat(auto-fill, 330px); align-items: flex-start; grid-column-gap: 10px; grid-row-gap: 50px; } .item { background: black; border-radius: 5px; } <div class="wrapper"> <div

Limit the width of a column to the width of a particular grid item

扶醉桌前 提交于 2019-11-28 02:07:15
I have this simple use case: an item title and description. The title should appear above the description and I want the title to determine the width of the entire column, also for the 'description' row. Is that possible with CSS Grid, and if so, how? This is the desired output: And that's the code, basically: .grid-container { display: grid; grid-template-columns: 1fr; } <div class="grid-container"> <div class="A"> DIV A contains the TITLE </div> <div class="B"> DIV B has much more text but I want its text to wrap to the width of div.A (no cut of words, just wrapping) </div> </div> Instead of

How can I force this CSS grid to wrap to a new line without specifying minmax sizes?

风流意气都作罢 提交于 2019-11-28 01:38:21
问题 I come from a heavy div/float background to build responsive sites (e.g. Bootstrap 3, Foundation) and used Flex box briefly but have been attempting to use Grid everywhere since it's been really great at solving a number of problems. I seem to run into "simple" problems like this all too often and feel like I'm missing some basics, and can't find the answer in docs. Anyways, to the code. Given a grid setup like so: display: grid; grid-auto-columns: max-content; grid-auto-flow: column; the

What is the difference between align-items vs. align-content in Grid Layout?

狂风中的少年 提交于 2019-11-28 01:29:21
I've read through A complete guide to Grid , but still confused with the differences between two sets of container properties, namely the " justify/align-items " vs. " justify/align-content ". My confusion revolves around the claim made by the author that the " -content " set are there because Sometimes the total size of your grid might be less than the size of its grid container I think this applies to both, not unique to the " -content " set. Could someone help explain this? Preferably using some graphical illustration as examples. Let's start with clarifying the terminology: Grid Container

CSS Grid unwanted column added automatically

末鹿安然 提交于 2019-11-28 01:27:28
Trying to group items in two separate line by CSS Grid using different class names. It works fine until in "red" group have no more elements then predefined rows (this case 3). Can I somehow put the 4th "red" element in new row? If there is only 3 "red" element, everything works fine. ul { display: grid; grid-template-columns: 1fr 1fr 1fr; } .blue { background-color: blue; } .red { background-color: red; grid-row-start: 5; } <ul> <li class="blue"> <h2>1</h2> </li> <li class="red"> <h2>2</h2> </li> <li class="blue"> <h2>3</h2> </li> <li class="blue"> <h2>4</h2> </li> <li class="red"> <h2>5</h2>

Make flex items have equal width in a row

天涯浪子 提交于 2019-11-28 00:28:16
If you look at the example below, I want the headers ( h4.child-title ) to have the same length within the parent container. But I'm not successful in achieving this. Any help is appreciated. .top-level { display: flex; flex-flow: row wrap; } .section { display: flex; flex-flow: row nowrap; border: 1px solid; margin-right: 12px; margin-top: 12px; } .section-child { display: flex; flex-flow: column nowrap; align-items: center; flex: 1 1 0; } .child-title { white-space: nowrap; } .vertical-separator { width: 1px; background-color: rgba(0, 0, 0, 0.3); margin: 8px; } <div class="top-level">

Getting columns to wrap in CSS Grid

你说的曾经没有我的故事 提交于 2019-11-27 23:44:36
问题 How can you specify the maximum number of columns when using display: grid; , with it automatically breaking when the content becomes too wide for the space (or smaller than a minimum size)? Is there a way to do this without media queries? For example, I have the following which won't break into a single column mode when there is not enough room for the content. #grid { display: grid; grid-template-columns: repeat(2, 1fr); grid-gap: 1em; } #grid > div { background-color: #ccddaa; } <div id=