Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> CSS

Đặt cỡ chữ với đơn vị Em trong CSS


Để đặt thuộc tính font-size trong CSS, bạn có thể dùng đơn vị em. Điều này hữu ích khi cần độ chính xác pixel cho văn bản. Mặc định 1em = 16px, 2em = 32px.

Ví dụ

<!DOCTYPE html> <html> <head> <style> .demo {    text-decoration: overline;    text-decoration-color: yellow;    font-size: 1.3em; } </style> </head> <body> <h1>Examination Details</h1> <p class="demo">Exam on 20th December.</p> <p class="demo2">Exam begins at 9AM.</p> </body> </html>

Kết quả

Đặt cỡ chữ với đơn vị Em trong CSS

Ví dụ khác

<!DOCTYPE html> <html> <head> <style> div {    text-align: justify;    text-justify: inter-word;    color: white;    background-color: gray;    font-size: 1.5em; } </style> </head> <body> <h2>Demo Heading</h2> <div>This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. </div> </body> </html>

Kết quả

Đặt cỡ chữ với đơn vị Em trong CSS