W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <head> <style> .container { position: relative; width: 100%; max-width: 400px; } .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: #f1f1f1; color: black; font-size: 16px; padding: 16px 30px; border: none; cursor: pointer; border-radius: 5px; text-align: center; } .container .btn:hover { background-color: black; color: white; } </style> </head> <body> <h1>图像上的按钮</h1> <p>为图像添加按钮:</p> <div class="container"> <img src="/i/photo/img_lights.jpg" alt="Snow" style="width:100%"> <button class="btn">按钮</button> </div> </body> </html>