File tree Expand file tree Collapse file tree 2 files changed +71
-0
lines changed
15-focus-within-pseudo-class Expand file tree Collapse file tree 2 files changed +71
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 " />
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6
+ < title > CSS - :focus-within pseudo class</ title >
7
+ < link rel ="stylesheet " href ="style.css " />
8
+ </ head >
9
+ < body >
10
+ <!--- The :focus-within CSS pseudo-class matches an element if the element or any of its descendants are focused.-->
11
+
12
+ <!-- Using focus-within pseudo class -->
13
+ < div class ="box ">
14
+ < textarea > Hello</ textarea >
15
+ </ div >
16
+
17
+ <!-- Using tabindex : allows developers to make HTML elements focusable, using the tab key
18
+ Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex
19
+ -->
20
+ < div class ="box ">
21
+ < div class ="box2 " tabindex ="0 "> World</ div >
22
+ </ div >
23
+
24
+ <!-- Read more: https://stackoverflow.com/questions/7876283/using-focus-to-style-outer-div -->
25
+ </ body >
26
+ </ html >
Original file line number Diff line number Diff line change
1
+ @import url ("https://fonts.googleapis.com/css2?family=Fira+Code&family=Lato&display=swap" );
2
+ body {
3
+ font-family : Lato, Fira Code, monospace;
4
+ display : flex;
5
+ width : 100vw ;
6
+ height : 100vh ;
7
+ justify-content : center;
8
+ align-items : center;
9
+ background-color : lightcyan;
10
+ gap : 20px ;
11
+ }
12
+ .box {
13
+ width : 600px ;
14
+ height : 400px ;
15
+ border : 2px dashed darkblue;
16
+ position : relative;
17
+ }
18
+ .box : focus-within {
19
+ border-color : red;
20
+ }
21
+ textarea {
22
+ resize : none;
23
+ width : 400px ;
24
+ height : 300px ;
25
+ text-align : center;
26
+ line-height : 300px ;
27
+ position : absolute;
28
+ top : 50px ;
29
+ left : 100px ;
30
+ outline : 1px solid blue;
31
+ font-size : 16px ;
32
+ }
33
+ .box2 {
34
+ resize : none;
35
+ width : 400px ;
36
+ height : 300px ;
37
+ text-align : center;
38
+ line-height : 300px ;
39
+ position : absolute;
40
+ top : 50px ;
41
+ left : 100px ;
42
+ outline : 2px solid purple;
43
+ background-color : white;
44
+ font-size : 16px ;
45
+ }
You can’t perform that action at this time.
0 commit comments