Shadows
With CSS you can create shadow effects!
ด้วย CSS คุณสามารถเพิ่มเงาให้กับข้อความและองค์ประกอบได้
ในบทเหล่านี้ คุณจะได้เรียนรู้เกี่ยวกับคุณสมบัติต่อไปนี้:
text-shadow
box-shadow
CSS text-shadow
คุณสมบัติใช้เงากับข้อความ
ในการใช้งานที่ง่ายที่สุด คุณจะต้องระบุเฉพาะเงาแนวนอน (2px) และเงาแนวตั้ง (2px):
h1
{
text-shadow: 2px 2px;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
text-shadow: 2px 2px;
}
</style>
</head>
<body>
<h1>Text-shadow effect!</h1>
</body>
</html>
จากนั้นเพิ่มสีให้กับเงา:
h1
{
text-shadow: 2px 2px red;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
text-shadow: 2px 2px red;
}
</style>
</head>
<body>
<h1>Text-shadow effect!</h1>
</body>
</html>
จากนั้นเพิ่มเอฟเฟกต์เบลอให้กับเงา:
h1
{
text-shadow: 2px 2px 5px red;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
text-shadow: 2px 2px 5px red;
}
</style>
</head>
<body>
<h1>Text-shadow effect!</h1>
</body>
</html>
ตัวอย่างต่อไปนี้แสดงข้อความสีขาวและมีเงาสีดำ:
h1
{
color: white;
text-shadow: 2px 2px 4px #000000;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: white;
text-shadow: 2px 2px 4px #000000;
}
</style>
</head>
<body>
<h1>Text-shadow effect!</h1>
</body>
</html>
ตัวอย่างต่อไปนี้แสดงเงาเรืองแสงนีออนสีแดง:
h1
{
text-shadow: 0 0 3px #FF0000;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
text-shadow: 0 0 3px #FF0000;
}
</style>
</head>
<body>
<h1>Text-shadow with red neon glow!</h1>
</body>
</html>
หากต้องการเพิ่มมากกว่าหนึ่งเงาให้กับข้อความ คุณสามารถเพิ่มรายการเงาที่คั่นด้วยเครื่องหมายจุลภาคได้
ตัวอย่างต่อไปนี้แสดงเงาเรืองแสงนีออนสีแดงและสีน้ำเงิน:
h1
{
text-shadow: 0 0 3px #FF0000, 0 0 5px #0000FF;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
text-shadow: 0 0 3px #FF0000, 0 0 5px #0000FF;
}
</style>
</head>
<body>
<h1>Text-shadow with red and blue neon glow!</h1>
</body>
</html>
ตัวอย่างต่อไปนี้แสดงข้อความสีขาวพร้อมเงาสีดำ สีน้ำเงิน และสีน้ำเงินเข้ม:
h1
{
color: white;
text-shadow: 1px 1px 2px black, 0 0 25px blue, 0 0 5px darkblue;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: white;
text-shadow: 1px 1px 2px black, 0 0 25px blue, 0 0 5px darkblue;
}
</style>
</head>
<body>
<h1>Text-shadow effect!</h1>
</body>
</html>
คุณยังสามารถใช้คุณสมบัติ text-shadow เพื่อสร้างเส้นขอบธรรมดารอบข้อความบางส่วน (โดยไม่มีเงา):
h1
{
color: coral;
text-shadow: -1px 0 black, 0 1px
black, 1px 0 black, 0 -1px black;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: coral;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
</style>
</head>
<body>
<h1>Border around text!</h1>
</body>
</html>