【问题标题】:CSS Grid auto populate selected columnsCSS Grid 自动填充选定的列
【发布时间】:2021-06-08 13:29:54
【问题描述】:

我只想自动填充第 2 列和第 3 列。我将制作一个 ES6 (javascript) map()。如您所见,段落/组件保留在同一列中。下面是反应代码,但基本上问题是 css。

我的 CSS:

export const WrapperServices = styled.div`
  position: absolute;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: auto;
  grid-gap: 2rem;
  align-items: center;
  justify-items: center;
  color: var(--white);
  margin: auto;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  height: 90%;
  width: 90%;
  max-width: 1280px;
  background: rgb(0, 0, 0, 0.5);
  border-radius: 0px;

  .first-column {
    grid-column: 1/2;
  }

  .second-and-third-column {
    // i dont no
  }
`
export const Service = styled.p`
  display: flex;
  justify-content: center;
  align-items: center;
`

我的 HTML (JSX)(使用 react 样式的组件):

<Wrapper>
      <StyledImg image={imageData}" />
      <WrapperServices>
      <span className="first-column">
              <h2>Defesa criminal</h2>
              <p>Conheça nossa atuação</p>
            </span>

            <span className="second-and-third-column">
              <Service>
                <GoLaw size="45" style={{ paddingRight: '10px' }} />
                {data.service1}
              </Service>

              // copy and paste <Service/> component 10 times for testing purpose.
            </span>
  </WrapperServices>
    </Wrapper>

【问题讨论】:

  • .second-and-third-column { grid-column: 2/3 }?
  • 嗨!不起作用。

标签: css reactjs css-grid styled-components


【解决方案1】:

我找到了一个不太优雅的解决方案:

.first-column {
    grid-column: 1/2;
    grid-row-start: 1;
    grid-row-end: 6;
  }

并删除网格项的跨度

【讨论】:

猜你喜欢
  • 2018-01-11
  • 2018-08-30
  • 1970-01-01
  • 2018-11-15
  • 1970-01-01
  • 2021-03-25
  • 1970-01-01
  • 2021-05-30
  • 1970-01-01
相关资源
最近更新 更多