How to make hover state on row table with CSS grid layout

后端 未结 5 1057
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 16:52

This a table that created with CSS Grid Layout, but I have a problem with it, I can\'t make hover state on each row.

I only want use CSS for this.

Can anyone

5条回答
  •  悲哀的现实
    2020-12-14 17:48

    Since you are treating this as a table, where the elements stay in the same row, you can also wrap each row in a DIV with "display" set to "contents." This forms an innocuous parent element that you use for hover, and then style the child elements. (display: contents is not yet supported in Edge, though.)

    .table {
      display: grid;
      grid-template-columns: [col-start] auto [col-end];
      grid-template-rows: [header-start] 50px [header-end row-start] auto [row-end];
      grid-auto-rows: auto;
      grid-auto-columns: auto;
      grid-gap: 1px;
      overflow: hidden;
      background: gray;
    }
    
    .table .row, .table .heading{
      padding: 10px;
      position: relative;
    }
    
    .heading {
      background: navy;
      color: #fff;
      grid-row: header;
    }
    
    .row span {
      position: relative;
      z-index: 2;
    }
    
    .rowWrapper{
      display: contents;
    }
    
    .rowWrapper:hover > div{
      background-color: orange;
    }
    Title 1
    Title 2
    Title 3
    Title 4
    Title 5
    Row 1
    Row 1
    Row 1
    Row 1
    Row 1
    Row 2
    Row 2
    Row 2
    Row 2
    Row 2
    Row 3
    Row 3
    Row 3
    Row 3
    Row 3

提交回复
热议问题