ในบทนี้ คุณจะได้เรียนรู้เกี่ยวกับคุณสมบัติต่อไปนี้:
text-decoration-line
text-decoration-color
text-decoration-style
text-decoration-thickness
text-decoration
text- decoration-line
คุณสมบัติที่ใช้ในการเพิ่ม เส้นตกแต่งเป็นข้อความ
เคล็ดลับ: คุณสามารถรวมค่าได้มากกว่าหนึ่งค่า เช่น ซ้อนทับ และ ขีดเส้นใต้เพื่อแสดงบรรทัดทั้งด้านบนและด้านล่างข้อความ
h1 {
text-decoration-line: overline;
}
h2 {
text-decoration-line: line-through;
}
h3 {
text-decoration-line: underline;
}
p {
text-decoration-line:
overline underline;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
text-decoration: overline;
}
h2 {
text-decoration: line-through;
}
h3 {
text-decoration: underline;
}
p.ex {
text-decoration: overline underline;
}
</style>
</head>
<body>
<h1>Overline text decoration</h1>
<h2>Line-through text decoration</h2>
<h3>Underline text decoration</h3>
<p class="ex">Overline and underline text decoration.</p>
<p><strong>Note:</strong> It is not recommended to underline text that is not a link, as this often confuses
the reader.</p>
</body>
</html>
หมายเหตุ: ไม่แนะนำให้ขีดเส้นใต้ข้อความที่ไม่ใช่ลิงก์ เนื่องจากจะทำให้ผู้อ่านสับสนบ่อยครั้ง
คุณสมบัติ text- decoration-color
ถูกนำมาใช้ กำหนดสีของเส้นตกแต่ง
h1 {
text-decoration-line: overline;
text-decoration-color:
red;
}
h2 {
text-decoration-line: line-through;
text-decoration-color:
blue;
}
h3 {
text-decoration-line: underline;
text-decoration-color:
green;
}
p {
text-decoration-line:
overline underline;
text-decoration-color: purple;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
text-decoration-line: overline;
text-decoration-color: red;
}
h2 {
text-decoration-line: line-through;
text-decoration-color: blue;
}
h3 {
text-decoration-line: underline;
text-decoration-color: green;
}
p {
text-decoration-line: overline underline;
text-decoration-color: purple;
}
</style>
</head>
<body>
<h1>Overline text decoration</h1>
<h2>Line-through text decoration</h2>
<h3>Underline text decoration</h3>
<p>Overline and underline text decoration.</p>
</body>
</html>
คุณสมบัติ text- decoration-style
ถูกนำมาใช้ กำหนดสไตล์เส้นตกแต่ง
h1 {
text-decoration-line: underline;
text-decoration-style:
solid;
}
h2 {
text-decoration-line: underline;
text-decoration-style: double;
}
h3 {
text-decoration-line: underline;
text-decoration-style: dotted;
}
p.ex1 {
text-decoration-line: underline;
text-decoration-style: dashed;
}
p.ex2 {
text-decoration-line: underline;
text-decoration-style: wavy;
}
p.ex3 {
text-decoration-line:
underline;
text-decoration-color: red;
text-decoration-style: wavy;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
text-decoration-line: underline;
text-decoration-style: solid; /* this is default */
}
h2 {
text-decoration-line: underline;
text-decoration-style: double;
}
h3 {
text-decoration-line: underline;
text-decoration-style: dotted;
}
p.ex1 {
text-decoration-line: underline;
text-decoration-style: dashed;
}
p.ex2 {
text-decoration-line: underline;
text-decoration-style: wavy;
}
p.ex3 {
text-decoration-line: underline;
text-decoration-color: red;
text-decoration-style: wavy;
}
</style>
</head>
<body>
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<p class="ex1">A paragraph.</p>
<p class="ex2">Another paragraph.</p>
<p class="ex3">Another paragraph.</p>
</body>
</html>
คุณสมบัติ text- decoration-thickness
ถูกนำมาใช้ กำหนดความหนาของเส้นตกแต่ง
h1 {
text-decoration-line: underline;
text-decoration-thickness: auto;
}
h2 {
text-decoration-line:
underline;
text-decoration-thickness: 5px;
}
h3 {
text-decoration-line: underline;
text-decoration-thickness: 25%;
}
p {
text-decoration-line: underline;
text-decoration-color: red;
text-decoration-style: double;
text-decoration-thickness: 5px;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
text-decoration-line: underline;
text-decoration-thickness: auto; /* this is default */
}
h2 {
text-decoration-line: underline;
text-decoration-thickness: 5px;
}
h3 {
text-decoration-line: underline;
text-decoration-thickness: 25%;
}
p {
text-decoration-line: underline;
text-decoration-color: red;
text-decoration-style: double;
text-decoration-thickness: 5px;
}
</style>
</head>
<body>
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<p>A paragraph.</p>
</body>
</html>
คุณสมบัติ text- decoration
เป็นการจดชวเลข คุณสมบัติสำหรับ:
ข้อความตกแต่งบรรทัด
(จำเป็น)
ข้อความตกแต่งสี
(ไม่จำเป็น)
ข้อความตกแต่งสไตล์
(ไม่จำเป็น)
ข้อความ-ตกแต่ง-ความหนา
(ไม่จำเป็น)
h1 {
text-decoration: underline;
}
h2 {
text-decoration: underline red;
}
h3 {
text-decoration: underline
red double;
}
p {
text-decoration: underline red double 5px;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
text-decoration: underline;
}
h2 {
text-decoration: underline red;
}
h3 {
text-decoration: underline red double;
}
p {
text-decoration: underline red double 5px;
}
</style>
</head>
<body>
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<p>A paragraph.</p>
</body>
</html>
ลิงก์ทั้งหมดใน HTML จะถูกขีดเส้นใต้ตามค่าเริ่มต้น บางครั้งคุณ เห็นว่าลิงก์มีรูปแบบไม่มีการขีดเส้นใต้ text- decoration: none;
ใช้ในการลบ ขีดเส้นใต้จากลิงก์ แบบนี้:
a {
text-decoration: none;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
a {
text-decoration: none;
}
</style>
</head>
<body>
<h1>Using text-decoration: none</h1>
<p>A link with no underline: <a href="https://www.w3schools.com">W3Schools.com</a></p>
</body>
</html>
ตั้งค่าคุณสมบัติการตกแต่งข้อความทั้งหมดในการประกาศเดียว
ระบุสีของการตกแต่งข้อความ
ระบุชนิดของการตกแต่งข้อความที่จะใช้ (ขีดเส้นใต้, ขีดเส้นใต้, ฯลฯ)
ระบุสไตล์การตกแต่งข้อความ (ทึบ จุด ฯลฯ)
ระบุความหนาของเส้นตกแต่งข้อความ