아래 사진들을 클릭해 보세요!
부모요소인 회색 테두리의 DIV 가 CSS - position : relative 로 설정 되어있습니다.
이렇게 CSS position 의 설정이 지정되면 해당 요소의 부모를 기준으로 자신의 위치값을 가져옵니다.
<style type="text/css">
.css_test {
border : 5px solid silver;
margin-bottom : 30px;
padding : 5px;
position : relative;
}
.css_test img {
cursor : pointer;
}
.css_test input {
border-radius : 5px;
border : 3px solid gray;
color : blue;
font-weight : bold;
margin-top : 10px;
padding : 7px;
text-align : center;
width : 300px;
}
</style>
아래 사진들을 클릭해 보세요!<br>
부모요소인 회색 테두리의 DIV 가 CSS - position : relative 로 설정 되어있습니다.<br>
이렇게 CSS position 의 설정이 지정되면 해당 요소의 부모를 기준으로 자신의 위치값을 가져옵니다.<br><br>
<div class="css_test">
<img src="https://t1.daumcdn.net/cfile/tistory/27210A38555ABF4229"
onclick="j_test(this)" /><br>
<input type="text" value="" />
</div>
<div class="css_test">
<img src="https://t1.daumcdn.net/cfile/tistory/261FC83454D7331705"
onclick="j_test(this)" /><br>
<input type="text" value="" />
</div>
<script type="text/javascript">
function j_test(o){
var pos = $(o)
.position();
$('input', $(o).parent()).val( '이미지의 position - left:' + pos.left + ', top:' + pos.top);
}
</script>