【问题标题】:CSS Grid minmax - need verification, pleaseCSS Grid minmax - 需要验证,请
【发布时间】:2021-09-27 12:26:03
【问题描述】:

我正在尝试以下需要响应的网格布局。所包含文本的宽度必须最大为 890 像素,并调整大小以适应手机。

我做了一些实验,“minmax(auto, 890px)”似乎有效 - 在 Chrome 开发工具、Microsoft Edge 和 Firefox 上进行了测试。

但是我怀疑这是正确的方法,因为我在任何地方都没有找到任何线索。我做对了吗?有更好更合适的方法来实现这一点吗?

CSS

article {
    display: grid;
    grid-template-columns: 1fr 1fr 0px minmax(auto, 890px) 0px 1fr 1fr;
    margin: 15vh 0 15vh 0 /* margin top and bottom of whole content */
}

article > * {
    grid-column: 4;
}

article > figure {
    grid-column: 1 / -1;
    margin: 20px 0;
}

.container {
    width: 85%;
    max-width: 1400px;
    margin: 0 auto
}

HTML

<div class="container">

<article>


        <h2>Lorem ipsum</h2>
        <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>

        <figure>
            <img src="https://mave.me/img/projects/full_placeholder.png">
        </figure>

        <h2>More lorem ipsum</h2>
        <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>

</article>

</div>

【问题讨论】:

  • fit-content(890px) 将是你所需要的我认为
  • 谢谢你,德克尔兹。它有效。

标签: css css-grid


【解决方案1】:

正确的方法是使用断点,并为不同的断点编写专用的 css。请参阅here 以供参考。 对于文章,您还可以设置 width: 100% 或其他任何值和 max-width: 890px 以自动调整宽度。

【讨论】:

  • 是的,我知道断点。但是我们不应该总是以最新的 css 为目标 - 甚至可能有一个后备? Css 网格被定义为现代 css 中断点的解决方案 - 不是我,而是 csstricks 等来源。但如果我错了,请原谅我,我对这个主题很无知
猜你喜欢
  • 2018-05-04
  • 1970-01-01
  • 2013-01-13
  • 2022-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-23
  • 1970-01-01
相关资源
最近更新 更多