CSS点击小图显示大图是一种常见的网页交互效果,通过CSS和JavaScript实现。用户点击小图后,大图会在页面上显示出来,通常用于图片预览或放大查看。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Click to Show Large Image</title>
<style>
.thumbnail {
cursor: pointer;
width: 100px;
height: 100px;
background-image: url('small-image.jpg');
background-size: cover;
}
.large-image {
display: none;
width: 500px;
height: 500px;
background-image: url('large-image.jpg');
background-size: cover;
}
.thumbnail:hover + .large-image {
display: block;
}
</style>
</head>
<body>
<div class="thumbnail"></div>
<div class="large-image"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript Click to Show Large Image</title>
<style>
.thumbnail {
cursor: pointer;
width: 100px;
height: 100px;
background-image: url('small-image.jpg');
background-size: cover;
}
.large-image {
display: none;
width: 500px;
height: 500px;
background-image: url('large-image.jpg');
background-size: cover;
}
</style>
</head>
<body>
<div class="thumbnail" onclick="showLargeImage()"></div>
<div class="large-image" id="largeImage"></div>
<script>
function showLargeImage() {
document.getElementById('largeImage').style.display = 'block';
}
</script>
</body>
</html>
通过以上方法,可以有效解决CSS点击小图显示大图过程中遇到的问题。
没有搜到相关的文章