# CSS Units

# Parent and Child Element

# Parent


 

 


...
    <div>
        <h1>HelloWorld</h1>
    </div>
...
1
2
3
4
5

# Child



 



...
    <div>
        <h1>HelloWorld</h1>
    </div>
...
1
2
3
4
5

# Units

# Percentage (%)


parent

child

width: 100%
width: 50%
width: 110%

# Viewport

  • vw = Relative to 1% of the width of the viewport.
  • vh = Relative to 1% of the height of the viewport.
Preview Full HTML

# REM

  • rem = Relative to font-size of the root element (html).
...
    <p class="p1">tag p with 1 rem</p>
    <p class="p2">tag p with 2 rem</p>
    <p class="p3">tag p with 3 rem</p>
...
1
2
3
4
5
.p1 {
    font-size: 1rem;
}

.p2 {
    font-size: 2rem;
}

.p3 {
    font-size: 3rem;
}
1
2
3
4
5
6
7
8
9
10
11
Preview Full HTML

What if we change root font size?

html{
    font-size: 32px;
}

.p1 {
    font-size: 1rem;
}

.p2 {
    font-size: 2rem;
}

.p3 {
    font-size: 3rem;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Preview Full HTML

# Box Shadow

box-shadow: 5px 5px 10px 1px rgba(0, 0, 0, 0.5);
1
  • Horizontal Length
  • Vertical Length
  • Blur Radius
  • Spread Radius
  • Color
;

# Google Font

html file

<html>
    <head>
        ...
        <link href="https://fonts.googleapis.com/css?family=Montserrat&display=swap" rel="stylesheet">
    </head>
...
</html>
1
2
3
4
5
6
7

css file

body{
    font-family: 'Montserrat', sans-serif;
}
1
2
3

# Workshop

# Simple Profile (Continues)


Preview Full HTML

index.html






 




























<html>

<head>
    <title>Simple Profile</title>
    <link rel="stylesheet" href="style1.css">
    <link href="https://fonts.googleapis.com/css?family=Montserrat&display=swap" rel="stylesheet">
</head>

<body>

    <div class="container textcenter">

        <div class="inBox">
            <h1 style="color: aliceblue">Hello My Name is Raknatee </h1>
            <p>Nice to meet you</p>
            <p>:D</p>

            <a href="https://www.facebook.com/raknatee.chokluechai?ref=bookmarks">
                This is my Facebook
            </a>
            <br>
            <img src="profile.jpg" style="width: 100px;margin: 30px; border-radius: 30%;">
            <br>




        </div>

    </div>

</body>

</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

style1.css





















 








































.container{
    background-image: url("https://images.unsplash.com/photo-1562874724-b33411b38141?ixlib=rb-1.2.1&auto=format&fit=crop&w=2801&q=80");
    height: 100%;
    background-position: center; 
    background-size: cover; 
    padding-top:40px
}
.inBox{
    padding: 30px;
    margin: 0 30px;
    background: #f7c6f280;
    color: aliceblue;
   
}
.textcenter{
    align-items: center;
    text-align: center;
    
}
body{
    font-family: 'Montserrat', sans-serif;
    margin: 0;
}
a{
   
    display: block;
    width: max-content;
    background-color:#3b5998 ;
    box-shadow: 0 5px 0 rgb(17, 9, 90);
    color: white;
    margin: auto;
    margin-top:40px;
    padding: 0.5rem 0.5rem;
    text-decoration: none;
    text-transform: uppercase;
}
.button {
    display: inline-block;
    padding: 15px 25px;
    font-size: 24px;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    outline: none;
    color: #fff;
    background-color: #4CAF50;
    border: none;
    border-radius: 15px;
    box-shadow: 0 9px #999;
  }
  
.button:hover {background-color: #3e8e41}
  
.button:active {
    background-color: #3e8e41;
    box-shadow: 0 5px #666;
    transform: translateY(4px);
  }


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60