Click here to Skip to main content
15,881,173 members
Articles / Web Development / HTML
Alternative
Tip/Trick

Show Image over an Image using CSS

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
25 Dec 2011CPOL 14.4K   1   1
If you have a large image, would you need to create multiple img tags? I would better create a div element with position:absolute to be over the image and set the width and height to cover the underlying image. Then set background-image to that div as url(line.gif) but the image should be...

If you have a large image, would you need to create multiple img tags? I would better create a div element with position:absolute to be over the image and set the width and height to cover the underlying image. Then set background-image to that div as url(line.gif) but the image should be corrected to have opacity. And set the background-repeat CSS value.


P.S.: I'd better add code to demonstrate:


HTML
<html>
<head>
	<title>Show Image over image</title>
	<style type="text/css"> 
		.line-decoration {
			background: repeat url(data:image/gif;base64,R0lGODlhDwABAIABAAAAAP///yH+EUNyZWF0ZWQgd2l0aCBHSU1QACH5BAEKAAEALAAAAAAPAAEAAAIEhIOpWAA7);
			position:absolute;
			width:100%;
			height:100%;
			left:0;
			top:0;
		}
	</style>
</head>
<body>
	<div style="position:absolute;">
		<img src="http://www.codeproject.com/Info/images/codeproject125x125.gif" />
		<div class="line-decoration"> </div>
	</div>
</body>
</html>

The image here is coded with base64 and it is just 1-pixel height line with the first three pixels black and 12 pixels opacity in GIF. So the outer div has absolute position and it will have the same size as the image. The inner div with the line-decoration class has background image and absolute position bound to the left-top corner of the outer div. So in my example, you don't have to know the image size or create multiple .imgB7 styles and elements.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) self employed
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralIf that's an alternate to the tip/trick, please provide exam... Pin
Ankur\m/29-Nov-11 3:20
professionalAnkur\m/29-Nov-11 3:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.