回答編集履歴

1

別の方法を追記

2021/03/18 06:16

投稿

Lhankor_Mhy
Lhankor_Mhy

スコア36138

test CHANGED
@@ -47,3 +47,45 @@
47
47
  }
48
48
 
49
49
  ```
50
+
51
+
52
+
53
+
54
+
55
+ # 別の方法を追記
56
+
57
+
58
+
59
+ ヘッダに`height: max-content`を当てて、内容物をオーバーフローさせれば、絶対配置を使う必要もなくていい感じですね。
60
+
61
+
62
+
63
+ [サンプル](https://jsfiddle.net/Lhankor_Mhy/Lgy15kw7/2/)
64
+
65
+
66
+
67
+ ```css
68
+
69
+ header{
70
+
71
+ width: 0;
72
+
73
+ height: max-content;
74
+
75
+ position: sticky;
76
+
77
+ opacity: 0.5;
78
+
79
+ top: 0;
80
+
81
+ }
82
+
83
+ header ul{
84
+
85
+ width: max-content;
86
+
87
+ background: pink;
88
+
89
+ }
90
+
91
+ ```