공감 버튼 누르면 이미지 표시
본문
답변 1
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_button_on_image
에 아래 코드를 복사해서 실행시켜 보세요.
대략적인 원인은 이미지위에 원하는 이미지를 같이 디스플레이 시키고, 그것의 스타일을 display: none으로 세팅해 놓았다가, 버튼을 누르면 display: block형태로 보여 주었다가 (필요하면 css transition도 적용시켜보세요.) 일정 시간 지나면
다시 display: none으로 세팅해 보세요
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<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: #555;
color: white;
font-size: 16px;
padding: 12px 24px;
border: none;
cursor: pointer;
border-radius: 5px;
text-align: center;
display: none;
}
.container .btn:hover {
background-color: black;
}
</style>
</head>
<body>
<h2>Button on Image</h2>
<p>Add a button to an image:</p>
<div class="container">
<img src="img_snow.jpg" alt="Snow" style="width:100%">
<button id="btnID" class="btn">Button</button>
</div>
<button onclick="myFunction()">Button</button>
<script>
function myFunction() {
var x = document.getElementById('btnID');
x.style.display = 'block';
setTimeout(function(){ x.style.display = 'none'; }, 2000);
}
</script>
</body>
</html>
답변을 작성하시기 전에 로그인 해주세요.