teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

質問の変更に合わせて追記

2019/12/10 10:15

投稿

Lhankor_Mhy
Lhankor_Mhy

スコア37474

answer CHANGED
@@ -13,4 +13,85 @@
13
13
  color: #ffffff
14
14
  }
15
15
  ```
16
- と、`!important`規則を使っているので、そちらのスタイルが優先されているのではないでしょうか。
16
+ と、`!important`規則を使っているので、そちらのスタイルが優先されているのではないでしょうか。
17
+
18
+ ### 質問の変更に合わせて追記
19
+ ご提示のサイトのCSSを抜粋して整形すると↓こんな感じです。
20
+ ```css
21
+ @keyframes sliderContentAnimation1{
22
+ from{
23
+ opacity: 0;
24
+ text-shadow: 0 0 20px #ffffff;
25
+ }
26
+ to{
27
+ opacity: 1;
28
+ text-shadow: 0 0 0 #ffffff;
29
+ }
30
+ }
31
+ .p-index-slider__item:nth-child(1).slick-active .p-index-slider__item-title{
32
+ animation: sliderContentAnimation1 1.2s ease forwards 2s;
33
+ transform: translateZ(0);
34
+ }
35
+ .p-index-slider__item-title{
36
+ color:inherit;
37
+ text-shadow:1px 2px 3px #808080 !important;
38
+ }
39
+ ```
40
+ text-shadowをCSSアニメさせているところ、`!important`規則でアニメーションを強制無効にしている感じです。Firefoxは`!important`が優先されてCSSアニメーションが無効になっていましたが、ChromeはCSSアニメーションが優先されて`!important`が無効化されていました。
41
+
42
+ わかりやすいサンプルを置いておきます。
43
+ [サンプル](https://jsfiddle.net/Lhankor_Mhy/xdgsp2ey/)
44
+ ```html
45
+ <p>
46
+ test
47
+ </p>
48
+ <p>
49
+ test
50
+ </p>
51
+ ```
52
+ ```css
53
+ p{
54
+ animation: test 1.2s ease forwards 2s;
55
+ }
56
+ @keyframes test {
57
+ 0% { color: #f00 }
58
+ 100% { color: #000 }
59
+ }
60
+ p{
61
+ color: #00f ;
62
+ }
63
+ p+p{
64
+ color: #00f !important;
65
+ }
66
+ ```
67
+ ChromeとFirefoxでは動作が違っているかと思います。
68
+
69
+ さてそれで、どちらが正しいのか、という話になりますが、CSS3の仕様書によりますと、
70
+ > The origin of a declaration is based on where it comes from and its importance is whether or not it is declared !important (see below). The precedence of the various origins is, in descending order:
71
+ 0. Transition declarations [css-transitions-1]
72
+ 0. Important user agent declarations
73
+ 0. Important user declarations
74
+ 0. Important author declarations
75
+ 0. Animation declarations [css-animations-1]
76
+ 0. Normal author declarations
77
+ 0. Normal user declarations
78
+ 0. Normal user agent declarations
79
+
80
+ > Declarations from origins earlier in this list win over declarations from later origins.
81
+ [Origin and Importance | CSS Cascading and Inheritance Level 3](https://www.w3.org/TR/css-cascade-3/#cascade-origin)
82
+
83
+ と、ありますから、CSSアニメーションより`!important`が優先されるべきで、Chromeのバグだろうと思います。
84
+  
85
+ ---
86
+
87
+ さて、具体的な解決方法ですが、キーフレームから`text-shadow`の部分を削除してしまえばいいかと思います。どうせ`!important`によって無効になるのですから、消してしまっても問題はないはずです。
88
+ ```css
89
+ @keyframes sliderContentAnimation1{
90
+ from{
91
+ opacity: 0;
92
+ }
93
+ to{
94
+ opacity: 1;
95
+ }
96
+ }
97
+ ```