回答編集履歴

2

他の方の回答が正しいことを追記

2019/07/10 11:56

投稿

syuus
syuus

スコア403

test CHANGED
@@ -1,3 +1,7 @@
1
+ **x_xさんの回答のほうが正攻法なので、そちらを参照してください。**
2
+
3
+
4
+
1
5
  単純に背景と文字を分けてしまえば簡単に実現できるかと思います。
2
6
 
3
7
 

1

別の解決策を追記

2019/07/10 11:56

投稿

syuus
syuus

スコア403

test CHANGED
@@ -45,3 +45,47 @@
45
45
  }
46
46
 
47
47
  ```
48
+
49
+
50
+
51
+ どうしても `::before` `::after` で書きたいのであれば、こんな書き方も可能です。
52
+
53
+ おすすめはしません。なるべくシンプルに書いたほうが良いかと思います。
54
+
55
+
56
+
57
+ ```css
58
+
59
+ p {
60
+
61
+ display: inline-block;
62
+
63
+ position: relative;
64
+
65
+ background: #fff;
66
+
67
+ }
68
+
69
+
70
+
71
+ p::after {
72
+
73
+ background: repeating-linear-gradient(45deg, green, green 5px, white 5px, white 10px, red 10px, red 15px);
74
+
75
+ content: '';
76
+
77
+ width: calc(100% + 10px);
78
+
79
+ height: calc(100% + 10px);
80
+
81
+ position: absolute;
82
+
83
+ top: -5px;
84
+
85
+ left: -5px;
86
+
87
+ z-index: -1;
88
+
89
+ }
90
+
91
+ ```