简体   繁体   English

如何将CSS样式应用于网格中的整个行?

[英]How can I apply a CSS style to the whole row in a grid?

I have a grid with rows and columns, each line forms a kind of section. 我有一个包含行和列的网格,每行形成一种节。 I would like to apply a shadow to each row but not to every element of the row. 我想为每行而不是每行元素添加阴影。 I would like to do it for the whole row. 我想整行地做。

I tried to encapsulate the rows in a "div" but it deconstructs the structure of the grid (unless we use "display: contents" but it doesn't work to apply a shadow). 我试图将行封装在“ div”中,但它会解构网格的结构(除非我们使用“ display:contents”,但它不适用于阴影)。

I would have liked to know if it is possible to wrap elements of a grid without breaking its structure? 我想知道是否有可能在不破坏网格结构的情况下包装网格元素?

Picture of a row of my grid (I would like to apply a shadow to the white block). 我的网格的一行图片 (我想在白色块上加上阴影)。

Something that would probably look like that: 可能看起来像这样:

HTML: HTML:

<div class="row-wrapper">
  <div class="column1"></div>
  <div class="column2"></div>
  <div class="column3"></div>
</div>

CSS CSS

.row-wrapper{
   box-shadow: 0px 0px 13px 0px rgba(82, 63, 105, 0.05);
}

Here is the original code (JSFiddle) 这是原始代码(JSFiddle)

Disclaimer: taking a wild guess that you are using css-grid. 免责声明:大胆猜测您正在使用css-grid。

fiddle 小提琴

CSS-Grid CSS网格

gist: 要旨:

<style>
  .header { grid-area: header; margin: 0.5rem; padding: 0.5rem; }
  .label-1 { grid-area: label-1; }
  .value-1 { grid-area: value-1; }
  .label-2 { grid-area: label-2; }
  .value-2 { grid-area: value-2; }
  .action { grid-area: action; }

  .row {
    display: grid;
    grid-template-areas:
      "header header header header header header header"
      "label-1 value-1 value-1 label-2 value-2 value-2 action";
    background-color: whitesmoke;
  }

  .rows, .row {
    box-shadow: 0 0.5rem 1rem 0 rgba(0, 0, 0, 0.1),
      0 0.5rem 1rem 0 rgba(0, 0, 0, 0.1);
    border-radius: 0.5rem; margin: 0.5rem; padding: 0.5rem;
  }
</style>

<div class="rows">
  <div class="header">Data</div>
  <div class="row">
    <div class="label-1"><label for="r1mass">Mass</label></div>
    <div class="value-1"><input id="r1mass" type="text" /></div>
    <div class="label-2"><label for="r1species">Species</label></div>
    <div class="value-2"><input id="r1species" type="text" /></div>
    <div class="action"><button>+</button></div>
  </div>
  <div class="row">
    <div class="label-1"><label for="r2mass">Mass</label></div>
    <div class="value-1"><input id="r2mass" type="text" /></div>
    <div class="label-2"><label for="r2species">Species</label></div>
    <div class="value-2"><input id="r2species" type="text" /></div>
    <div class="action"><button>+</button></div>
  </div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM