使用 CSS 设置按钮在图像上
你可以尝试运行以下代码将按钮设置在图像上
示例
<!DOCTYPE html>
<html>
<head>
<style>
.box {
position: relative;
width: 100%;
max-width: 250px;
}
.box img {
width: 100%;
height: auto;
}
.box .btn {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<div class = "box">
<img src = "https://tutorialspoint.com/videotutorials/images/current_affairs_home.jpg" alt = "Current Affairs">
<button class = "btn">Button</button>
</div>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP