質問編集履歴
2
コード修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,37 +16,96 @@
|
|
16
16
|
助言を頂ければと思います。
|
17
17
|
よろしくお願いします。
|
18
18
|
|
19
|
+
いただいたアドバイスを元に修正とテーブル部全体のコードも載せました。
|
20
|
+
現状やはり1行目と2行目の固定ができない状況です。
|
21
|
+
|
19
22
|
```html
|
23
|
+
{% set n = namespace(store = '') %}
|
20
|
-
|
24
|
+
{% set m = namespace(shiftname = '') %}
|
25
|
+
{% set l = namespace(loopcnt = 1) %}
|
21
|
-
|
26
|
+
{% for post in posts %}
|
22
|
-
{%
|
27
|
+
{% if n.store != post.store %}
|
23
|
-
{% if
|
28
|
+
{% if not loop.first %}
|
24
|
-
<
|
29
|
+
</tbody>
|
25
|
-
<
|
30
|
+
</table>
|
31
|
+
</div>
|
26
32
|
{% endif %}
|
33
|
+
<div class="table-responsive">
|
34
|
+
<table class="table table-bordered border-primary">
|
35
|
+
<thead class="fixedcolumn">
|
36
|
+
<tr>
|
37
|
+
{% for store in poststore %}
|
38
|
+
{% if store.store_name == post.store %}
|
39
|
+
<th class="fixedtable" style="width: 150px;"><a href="/store?store_no={{ post.store }}">{{ store.store_name }}</a></th>
|
40
|
+
<th colspan={{ day_count }} style="text-align: left;">{{ store.shift_time }}</th>
|
41
|
+
{% endif %}
|
42
|
+
{% endfor %}
|
43
|
+
</tr>
|
44
|
+
<tr>
|
45
|
+
<th class="fixedtable">氏名</th>
|
46
|
+
{% for i in range(1,day_count+1) %}
|
47
|
+
<th style="font-size: 0.75rem;">{{ i }}日</th>
|
48
|
+
{% endfor %}
|
49
|
+
</tr>
|
50
|
+
</thead>
|
51
|
+
<tbody>
|
52
|
+
{% endif %}
|
53
|
+
{% if m.shiftname != post.name %}
|
54
|
+
<tr>
|
55
|
+
<td class="fixedtable"><a href="/name?staff_name={{post.name}}">{{ post.name }}</a></td>
|
56
|
+
<td>{{ post.shift }}</td>
|
57
|
+
{% set l.loopcnt = l.loopcnt + 1 %}
|
58
|
+
{% else %}
|
59
|
+
{% if l.loopcnt == day_count %}
|
60
|
+
<td>{{ post.shift }}</td>
|
61
|
+
</tr>
|
62
|
+
{% set l.loopcnt = 1 %}
|
63
|
+
{% else %}
|
64
|
+
<td>{{ post.shift }}</td>
|
65
|
+
{% set l.loopcnt = l.loopcnt + 1 %}
|
66
|
+
{% endif %}
|
67
|
+
{% endif %}
|
68
|
+
{% set m.shiftname = post.name %}
|
69
|
+
{% set n.store = post.store %}
|
27
70
|
{% endfor %}
|
71
|
+
</table>
|
28
|
-
</
|
72
|
+
</div>
|
29
|
-
<tr>
|
30
|
-
<th class="fixedtable">氏名</th>
|
31
|
-
{% for i in range(1,day_count+1) %}
|
32
|
-
<th style="font-size: 0.75rem;">{{ i }}日</th>
|
33
|
-
{% endfor %}
|
34
|
-
</tr>
|
35
73
|
```
|
74
|
+
|
36
75
|
```CSS
|
37
|
-
|
76
|
+
thead tr{
|
77
|
+
height: 60px;
|
78
|
+
}
|
79
|
+
|
80
|
+
.fixedcolumn tr:first-child th {
|
38
81
|
position: -webkit-sticky;
|
39
82
|
position: sticky;
|
40
|
-
|
83
|
+
top: 0;
|
41
84
|
background-color: #202020 !important;
|
42
85
|
color: white !important;
|
43
86
|
}
|
44
87
|
|
45
|
-
.fixedcolumn th {
|
88
|
+
.fixedcolumn tr:nth-child(2) th {
|
46
89
|
position: -webkit-sticky;
|
47
90
|
position: sticky;
|
48
|
-
top:
|
91
|
+
top: 60px;
|
49
92
|
background-color: #202020 !important;
|
50
93
|
color: white !important;
|
51
94
|
}
|
95
|
+
|
96
|
+
.fixedcolumn tr:first-child th:first-child {
|
97
|
+
z-index: 1;
|
98
|
+
}
|
99
|
+
|
100
|
+
.fixedcolumn tr:nth-child(2) th:first-child{
|
101
|
+
z-index: 1;
|
102
|
+
}
|
103
|
+
|
104
|
+
.fixedtable {
|
105
|
+
position: -webkit-sticky;
|
106
|
+
position: sticky;
|
107
|
+
left: 0;
|
108
|
+
background-color: #202020 !important;
|
109
|
+
color: white !important;
|
110
|
+
}
|
52
111
|
```
|
1
行と列の表記間違い修正
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
CSSの「sticky」で
|
1
|
+
CSSの「sticky」で行を固定したいけれども固定されない
|
body
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PythonでFlaskを使ってシフト表を出力するアプリを作っています。
|
2
2
|
1ヶ月表示するので左端の名前部分と日付部分はスクロールしても固定したいと思い調べた結果
|
3
3
|
CSSにて「position: sticky;」を指定するというところは理解できました。
|
4
|
-
|
4
|
+
まず列の固定でtableの最初の項目に「fixedtable」というclassをつけて動くのを確認しました。
|
5
|
-
その後
|
5
|
+
その後同じように行を固定しようと同じように「fixedcolumn」というclassをつけてみたところ全く動作せず詰まってしまいました。
|
6
6
|
|
7
7
|
以下の行動は試してみました。
|
8
8
|
・ググってみて「sticky」とは親要素内でしか動かないという仕組みの理解
|