แบบการสร้าง: ปุ่มบนภาพ
เรียนรู้วิธีการใช้ CSS เพื่อเพิ่มปุ่มบนภาพ
ปุ่มบนภาพ

แบบการเพิ่มปุ่มบนภาพ
ขั้นที่ 1 - เพิ่ม HTML:
<div class="container"> <img src="img_snow.jpg" alt="Snow"> <button class="btn">Button</button> </div>
ขั้นที่ 2 - เพิ่ม CSS:
/* ต้องการมีกล่องเพื่อจัดตั้งตำแหน่งปุ่ม และปรับขนาดความกว้างตามที่ต้องการ */ .container { position: relative; width: 50%; } /* ทำให้ภาพสามารถปรับตัวเองตามตารางแบบการเคลื่อนไหว */ .container img { width: 100%; height: auto; } /* สำหรับตั้งรูปแบบสำหรับปุ่ม และจัดตั้งให้ปุ่มตั้งอยู่กลางภาพหรือสื่อ */ .container .btn { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); background-color: #555; color: white; font-size: 16px; padding: 12px 24px; border: none; cursor: pointer; border-radius: 5px; } .container .btn:hover { background-color: black; }