【问题标题】:Why doesn't min-content work with auto-fill or auto-fit?为什么 min-content 不适用于自动填充或自动调整?
【发布时间】:2019-03-01 10:10:58
【问题描述】:

基本上,我不明白为什么会这样:

.grid {
  display: grid;
  grid-template-columns: repeat(4, min-content);
}

但这不起作用:

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, min-content);
}

我真的希望使后一种功能成为可能。还有其他方法可以让它发挥作用吗?

【问题讨论】:

    标签: css css-grid fluid-layout css-multicolumn-layout


    【解决方案1】:

    第二条规则不起作用,因为min-content 是一个内在的大小调整函数

    § 7.2.2.1. Syntax of repeat()

    • 无法组合自动重复(auto-fillauto-fit) 具有固有灵活尺寸。

    § 11. Grid Sizing

    【讨论】:

    • 我也想知道为什么
    • @DavidGenger,当您达到规范级别时,您就在源头上。 “为什么”只能由规范编写者和浏览器实现者来回答。可能是由于技术复杂性、与其他功能的冲突,或者只是一个需要在岔路口做出的选择。谁知道?但希望这个问题在 Grid Level 2 中得到解决。
    • 没有意义的是为什么它对repeat 很重要,无论它是否是内在大小。归根结底,仍然会计算大小,那么为什么浏览器不能直接使用由固有大小调整功能计算得出的大小?
    【解决方案2】:

    我已经解决了这个问题

    grid-template-columns: repeat(auto-fill, minmax(0, max-content));

    这可确保创建的网格轨道具有非“固有”的最小尺寸,同时允许轨道根据max-content 扩展以适应。我有时根据用例使用auto-fit 而不是auto-fill,但两者都应该工作。

    【讨论】:

    • 不会换行,而是挤压元素
    猜你喜欢
    • 2021-10-31
    • 2019-01-06
    • 2018-07-16
    • 1970-01-01
    • 2021-10-31
    • 2013-09-11
    • 2019-12-26
    相关资源
    最近更新 更多