Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> CSS

การตั้งค่าขนาดตัวอักษรด้วย Em ใน CSS


ในการตั้งค่าคุณสมบัติขนาดฟอนต์ใน CSS คุณสามารถใช้ em สิ่งนี้มีประโยชน์เมื่อคุณต้องการความแม่นยำของพิกเซลสำหรับข้อความ โดยค่าเริ่มต้น 1em =16px และ 2em =32px

ตัวอย่าง

<!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>

ผลลัพธ์

การตั้งค่าขนาดตัวอักษรด้วย Em ใน CSS

ตัวอย่าง

เรามาดูตัวอย่างอื่นกัน −

<!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>

ผลลัพธ์

การตั้งค่าขนาดตัวอักษรด้วย Em ใน CSS