css - 网格列不起作用?

标签 css css-grid

我有这个标记

<main>
<section class="download">
  <img src="media/icon.svg" alt="TOX chat icon" width="345" height="280">
  <div class="download_desc">
    <h1>A New Kind of Instant Messaging</h1>
    <p>
      Whether it's corporations or governments, digital surveillance today is widespread. Tox is easy-to-use software that connects
      you with friends and family without anyone else listening in. While other big-name services require you to pay
      for features, Tox is completely free and comes without advertising — forever.
    </p>
  </div>
</section>

并应用 CSS:

    main {
  display: grid;
  grid-template-rows: 750px 500px 815px 815px 180px;
  grid-template-columns: repeat(6, 1fr);
}

.download {
  background-color: #414141;
  color: white;
}

.download_desc {
  grid-column: 2/6;
}

由于某种原因,网格列在这种情况下根本不起作用。 divdownload_desc类(class)仍然在第一列,而不是我想要的从第二列到第六列。

如果我直接将其应用到.download,它就会起作用。类(class),但不是 child 。

为什么?

最佳答案

您的问题是您的网格是“main”元素,而“download_desc”位于“download”部分标记内。

尝试移动:

display: grid;
grid-template-rows: 750px 500px 815px 815px 180px;
grid-template-columns: repeat(6, 1fr);

到“下载”类。

关于css - 网格列不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48686526/

相关文章:

html - 如何在 table/flex 中使用 100% 高度的图像?

html - 仅CSS的砌体布局

html - 应用 CSS 网格时 Owl Carousel 2 不工作

css - 列出未垂直居中的元素符号点

jquery - CSS 背景位置 a :hover rollover, 改变其他元素?

css - 使用网格 css 重新排序引导列内的 block

html - 用于更改内容数量的网格布局自动高度

html - CSS 网格 - 在 2 个水平 div 之间自动填充

html - 如何创建一个 DIV,它在 :hover (for desktop) and on tap (for touch devices) using CSS? 上下拉另一个 DIV

html - 悬停时的过渡效果