CSS-GRID:将可点击的div添加到布局

CSS-GRID: add a clickable div to layout

我有这些使用grid-css构建的卡。问题是我需要使屏幕快照中突出显示的卡的一部分可单击并用包裹(除"单独"外,所有其他均可单击)。 当我尝试这样做时,它完全破坏了我的布局。 [![在此处输入图片描述] [1]] [1]
我是CSS网格的新手,将不胜感激。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
    Row 1
   
     
        <span> Info</span> <span> Separate</span>
     
   
    Cell 1
    Cell 2
    Cell 3
 
 
   
    Row 1
   
     
        <span> Info</span> <span> Separate</span>
     
   
    Cell 1
    Cell 2
    Cell 3
 


.outer {
  display: grid;
  grid-template-columns: 5px repeat(3, auto) auto;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid #eee;
}

.color {
  grid-row-start: span 2;
  background: purple !important;
}

.row {
  padding: 1rem;
  grid-column: 2/-2;
}

.info {
  padding: 1rem 0;
  grid-row-start: span 2;
  display: flex;
}

.info-inner {
  padding: 1rem;
  border-left: 1px solid #eee;
}

.cell {
  padding: 1rem;
}

.bottom-row {
  border-bottom: 1px solid #eee;
}

.wrapper {
  display: contents;
  cursor: pointer;
}

.wrapper:last-child > * {
  border-bottom: 0;
}

您需要为要跨度的类创建一个单独的类,然后使用:not函数忽略该类,使其不被选中,并告诉光标是初始的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
.outer {
  display: grid;
  grid-template-columns: 5px repeat(3, auto) auto;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid #eee;
}

.color {
  grid-row-start: span 2;
  background: purple !important;
}

.row {
  padding: 1rem;
  grid-column: 2/-2;
}

.info {
  padding: 1rem 0;
  grid-row-start: span 2;
  display: flex;
}

.info-inner {
  padding: 1rem;
  border-left: 1px solid #eee;
}

.seperate:not(.wrapper) {
    cursor: initial;
}

.cell {
  padding: 1rem;
}

.bottom-row {
  border-bottom: 1px solid #eee;
 
}

.wrapper {
  display: contents;  
  cursor: pointer;

}

.wrapper:last-child > * {
  border-bottom: 0;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    Row 1
   
     
        <span> Info</span> <span class="seperate"> Separate</span>
     
   
    Cell 1
    Cell 2
    Cell 3
 
 
   
    Row 1
   
     
        <span> Info</span> <span class="seperate"> Separate</span>
     
   
    Cell 1
    Cell 2
    Cell 3