:
다음은 예입니다. 그러나 그것을 덮고있는 배경을 가진 image_tag를 갖는 것은 불가능합니다.
http://jsfiddle.net/QyMkh/
먼저 모든 이미지를 포함하는 사업부를 넣어 :이 최종 코드
: 가장 깨끗한 방법은 사용하는 jQuery를합니다. div에는 클래스가 있어야하며 이미지에는 반드시 필요하지 않습니다.
<div class="image">
<img src="http://upload.wikimedia.org/wikipedia/commons/4/42/Papua_New_Guinea_map.png" />
<img src="http://upload.wikimedia.org/wikipedia/commons/4/42/Papua_New_Guinea_map.png" />
<img src="http://upload.wikimedia.org/wikipedia/commons/4/42/Papua_New_Guinea_map.png" />
</div>
그런 다음 닫는 </BODY> 전에 HTML이 jQuery를 블록을 추가 :
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
// store in a variable the url of the image that will be used as background
var url = 'http://upload.wikimedia.org/wikipedia/commons/7/7a/Basketball.png';
// select every image_tag that is children of the div with the class 'image'
jQuery('.image img').each(function() {
// every child image will be wrapped inside generated divs with a class 'img-wrap'
$(this).wrap('<div class="img-wrap"></div>');
});
// After the images are wrapped, insert the image tag that will work as background, note that instead of using the source I'm using the variable that stores it.
$('<img src="' + url + '" class="logo" />').prependTo('.img-wrap');
</script>
마지막으로 원하는 효과를 얻기 위해 그 스타일 선언을 추가합니다.
<style type="text/css">
.img-wrap{position:relative}
.img-wrap img.logo{position:absolute; top:0; left:0}
</style>
이 코드는 다음 번에 편집하려고 할 때 불필요한 마크 업없이 HTML 문서를 유지합니다. image_tag를 배경으로 사용하면 css로 너비와 높이의 크기를 조정할 수 있다는 이점이 있습니다.당신은 더 많은 유연성을 원하는 경우
.img-wrap img.logo { height: 170px; left: 75px; position: absolute; top: 50px; width: 170px}
는이를 종료하려면 예를 들어, 당신은 image_tags는 사업부 컨테이너 수 싶지 않아,이 작업을 수행 : 스타일이 새로운 규칙을 추가보십시오 jQuery를이 라인을 대체 블록이
jQuery('.image').each(function() {
와
jQuery('.image img').each(function() {
및 각
,399,961에 클래스 = "이미지"를 추가
코드가 단순 해졌고 이제는 두 개의 이미지가 있으므로 그 코드에 뭔가를 추가 할 수있는 방법이 있으므로 로고 .png 이미지가 picture.jpg 위에 표시되도록 할 것입니까? 또는 "전경"과 같은 "배경"텍스트를 대체 할 수 있습니까? –
불가능한 배경 이미지는 요소 위에있을 수 없습니다. –
png 이미지가 jpg보다 작은 경우. 그러나 배경 크기가 이미지보다 큰 경우 예, 이미지 아래에있을 수 있습니다. 이는 배경 작업을 경계로 만들고 싶을 때 잘 작동합니다. 다음은 예입니다. http://jsfiddle.net/jNpaH/5/ –