Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

วิธีสร้างข้อความตัวใหญ่ (Big) ด้วย JavaScript

ใช้เมธอด big() ของ String ทำให้ข้อความแสดงใหญ่ขึ้น เหมือนแท็ก <big> (deprecated ใน HTML5)

ตัวอย่าง

<html>
  <head>
    <title>JavaScript String big() Method</title>
  </head>
  <body>
    <script>
      var str = new String("Demo Text");
      document.write("Following is bigger text: " + str.big());
    </script>
  </body>
</html>

ผลลัพธ์

<big>Demo Text</big>

⚠️ Legacy method – <big> deprecated ใช้ CSS แทน:

/* CSS */
.big-text { font-size: 1.2em; } /* หรือ larger, 120%, 1.5rem */

/* JavaScript */
element.style.fontSize = "1.2em";

Font size keywords

Keywordประมาณ
xx-small~9px
x-small~10px
small~13px
medium~16px (default)
large~18px
x-large~24px
xx-large~32px
smallerเล็กลง 1 ขนาดจาก parent
largerใหญ่ขึ้น 1 ขนาดจาก parent