DIV on top of another DIV without absolute positioning ?!http://forums.asp.net/t/1167640.aspx/1?DIV+on+top+of+another+DIV+without+absolute+positioning+Mon, 08 Oct 2007 21:31:43 -040011676401946220http://forums.asp.net/p/1167640/1946220.aspx/1?DIV+on+top+of+another+DIV+without+absolute+positioning+DIV on top of another DIV without absolute positioning ?! <p>&nbsp;I need to have a bottom div (its got a big image) and there should be a small top div with another image - overlaying the big image. The challenge here is i should not position the div's &quot;absolute&quot; - it should be relative but one div on top of the other. Any help regarding this would be very much appreciated.</p> <p>Thanks in advance.&nbsp;</p> 2007-10-08T18:36:50-04:001946256http://forums.asp.net/p/1167640/1946256.aspx/1?Re+DIV+on+top+of+another+DIV+without+absolute+positioning+Re: DIV on top of another DIV without absolute positioning ?! <p>&nbsp;You could nest the top div inside the bottom div and use the z-index css property to push it on top of the bottom div.<br> </p> 2007-10-08T18:58:17-04:001946341http://forums.asp.net/p/1167640/1946341.aspx/1?Re+DIV+on+top+of+another+DIV+without+absolute+positioning+Re: DIV on top of another DIV without absolute positioning ?! <p>&nbsp;If you don't mind, can you give me an example. Thanks.<br> </p> 2007-10-08T19:55:37-04:001946389http://forums.asp.net/p/1167640/1946389.aspx/1?Re+DIV+on+top+of+another+DIV+without+absolute+positioning+Re: DIV on top of another DIV without absolute positioning ?! <p>If your &quot;outer&quot; div has a big image and you want something to go on top of the image, then you need&nbsp;to use it&nbsp;as a background image&nbsp;and nest your &quot;inner&quot; div appropriately.&nbsp; For example...</p> <pre class="prettyprint">&lt;div style=&quot;background-image:url(image.jpg);&quot;&gt; &lt;div style=&quot;position:relative; top:10px; left:20px;&quot;&gt; &lt;img src=&quot;inside_image.jpg&quot; /&gt; &lt;/div&gt; &lt;/div&gt;</pre>&nbsp;<br> Hope this helps!&nbsp; Please mark the helpful post(s) as <strong>Answer</strong>. 2007-10-08T20:26:15-04:001946392http://forums.asp.net/p/1167640/1946392.aspx/1?Re+DIV+on+top+of+another+DIV+without+absolute+positioning+Re: DIV on top of another DIV without absolute positioning ?! <p>&nbsp;Thanks. But the problem is i cannot use the big image as background !! it has to be inside an &lt;img&gt; tag and the small image on top of it !!<br> </p> 2007-10-08T20:28:45-04:001946393http://forums.asp.net/p/1167640/1946393.aspx/1?Re+DIV+on+top+of+another+DIV+without+absolute+positioning+Re: DIV on top of another DIV without absolute positioning ?! <p>&nbsp;sure thing:</p> <p>html:</p> <p>&lt;div id=&quot;bottom&quot;&gt;</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;div id=&quot;top&quot;&gt;stuff in the top&lt;/div&gt;</p> <p>&lt;/div&gt;&nbsp;</p> <p>css:</p> <p>#bottom{</p> <p>&nbsp;&nbsp;&nbsp; width: 200px;<br> &nbsp;&nbsp;&nbsp; height: 200px;<br> &nbsp;&nbsp;&nbsp; background-color: black;<br> </p> <p>}</p> <p>#top{</p> <p>&nbsp;&nbsp;&nbsp; width:100px;<br> &nbsp;&nbsp;&nbsp; height:200px;<br> &nbsp;&nbsp;&nbsp; background-color:red;<br> </p> <p>&nbsp;&nbsp;&nbsp;<b> z-index: 999; &nbsp; &nbsp;</b>&nbsp; &lt;-- the z index property will push the #top div above the bottom div<br> </p> <p>}&nbsp;&nbsp; <br> &nbsp;</p> 2007-10-08T20:28:55-04:001946400http://forums.asp.net/p/1167640/1946400.aspx/1?Re+DIV+on+top+of+another+DIV+without+absolute+positioning+Re: DIV on top of another DIV without absolute positioning ?! <p></p> <blockquote><span class="icon-blockquote"></span> <h4>me_myself</h4> But the problem is i cannot use the big image as background !! it has to be inside an &lt;img&gt; tag and the small image on top of it!!</blockquote> <p>It <em>has</em> to be an IMG tag?&nbsp; That's stupid.&nbsp; If it's going behind another image then it truly is a background, so your&nbsp;requirements are ridiculous. </p> <p>I see no reason for doing it this way, but whatever you say... [^o)] </p> <p>You will <u>need</u> to use absolute positioning to accomplish this&nbsp;then.</p> <p>Best regards...</p> 2007-10-08T20:33:11-04:001946403http://forums.asp.net/p/1167640/1946403.aspx/1?Re+DIV+on+top+of+another+DIV+without+absolute+positioning+Re: DIV on top of another DIV without absolute positioning ?! I used the below code - something doesn't seem to fit !! It does not overlay properly !!<br> <p>&nbsp;</p> <pre class="prettyprint">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt; &lt;html&gt; &lt;head&gt; &lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt; &lt;!-- #bottom{ width: 200px; height: 200px; background-color: black; } #top{ width:100px; height:200px; background-color:red; z-index: 999; } --&gt; &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id=&quot;bottom&quot;&gt; &lt;div&gt;&lt;img src=&quot;images/big.gif&quot; width=&quot;529&quot; height=&quot;332&quot; /&gt;&lt;/div&gt; &lt;div id=&quot;top&quot;&gt;&lt;img src=&quot;images/small.gif&quot; width=&quot;20&quot; height=&quot;122&quot; /&gt;&lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt;</pre>&nbsp;&nbsp; 2007-10-08T20:34:37-04:001946407http://forums.asp.net/p/1167640/1946407.aspx/1?Re+DIV+on+top+of+another+DIV+without+absolute+positioning+Re: DIV on top of another DIV without absolute positioning ?! <p>&nbsp;</p> <pre class="prettyprint"><blockquote> <h4>me_myself</h4> &lt;div id=&quot;bottom&quot;&gt;</blockquote> &lt;div&gt;&lt;img src=&quot;images/big.gif&quot; width=&quot;529&quot; height=&quot;332&quot; /&gt;&lt;/div&gt; &lt;div id=&quot;top&quot;&gt;&lt;img src=&quot;images/small.gif&quot; width=&quot;20&quot; height=&quot;122&quot; /&gt;&lt;/div&gt; &lt;/div&gt; <blockquote></blockquote></pre><pre class="prettyprint">&nbsp;</pre>I would try removing the div tags from around the image.<br> 2007-10-08T20:37:22-04:001946409http://forums.asp.net/p/1167640/1946409.aspx/1?Re+DIV+on+top+of+another+DIV+without+absolute+positioning+Re: DIV on top of another DIV without absolute positioning ?! <p>&nbsp;Josh is right.&nbsp; I don't see any reason why you couldn't just make it a background image.&nbsp; It would be a lot easier that way.<br> </p> 2007-10-08T20:38:51-04:001946410http://forums.asp.net/p/1167640/1946410.aspx/1?Re+DIV+on+top+of+another+DIV+without+absolute+positioning+Re: DIV on top of another DIV without absolute positioning ?! <p></p> <blockquote><span class="icon-blockquote"></span> <h4>JoshStodola</h4> <p></p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>me_myself</h4> But the problem is i cannot use the big image as background !! it has to be inside an &lt;img&gt; tag and the small image on top of it!!</blockquote> <p></p> <p>It <em>has</em> to be an IMG tag?&nbsp; That's stupid.&nbsp; If it's going behind another image then it truly is a background, so your&nbsp;requirements are ridiculous. </p> <p>I see no reason for doing it this way, but whatever you say... <img src="http://forums.asp.net/emoticons/emotion-40.gif" alt="Hmm"> </p> <p>You will <u>need</u> to use absolute positioning to accomplish this&nbsp;then.</p> <p>Best regards...</p> <p></p> </blockquote> &nbsp; <p></p> <p>The requirement is such that both images loads dynamically, when you click on the small image (top) the bottom image changes/modifies accordingly - that was the reason i am not able to have that as a static background. Thanks.&nbsp;</p> 2007-10-08T20:39:20-04:001946415http://forums.asp.net/p/1167640/1946415.aspx/1?Re+DIV+on+top+of+another+DIV+without+absolute+positioning+Re: DIV on top of another DIV without absolute positioning ?! <p>Pfff, you call that a reason?!&nbsp; That's a dumb reason to disregards background images!!&nbsp; You can change them just as easily/dynamically as you would otherwise.&nbsp; Keep an open mind,&nbsp;instead of instantly saying &quot;Oh, I cant use background images NO WAY!!!&quot;</p> 2007-10-08T20:43:57-04:001946421http://forums.asp.net/p/1167640/1946421.aspx/1?Re+DIV+on+top+of+another+DIV+without+absolute+positioning+Re: DIV on top of another DIV without absolute positioning ?! <p>That's right: you can use javascript to change the background image of the bottom div. just add a javascript function that changes the background-image property of the bottom div and call the function on the onclick() of the image in the top div.&nbsp;</p> 2007-10-08T20:47:13-04:001946429http://forums.asp.net/p/1167640/1946429.aspx/1?Re+DIV+on+top+of+another+DIV+without+absolute+positioning+Re: DIV on top of another DIV without absolute positioning ?! <p>Alrighty, here it goes - i am creating a web map and trying to place a slider on top of the map. The map should be inside a div and the slider on top of the map should also be in a div !!!!!!!!!!!!!!!!!!!!!!</p> <p>Any ideas please ;)<br> &nbsp;</p> 2007-10-08T20:53:58-04:001946461http://forums.asp.net/p/1167640/1946461.aspx/1?Re+DIV+on+top+of+another+DIV+without+absolute+positioning+Re: DIV on top of another DIV without absolute positioning ?! <p>How about if you place the top div below the bottom div and then use a negative top-margin on the top div something like this:</p> <pre class="prettyprint">&lt;div id=&quot;bottom&quot;&gt; &lt;img alt=&quot;map&quot; src=&quot;map.jpg&quot; /&gt; &lt;/div&gt; &lt;div id=&quot;top&quot; style=&quot;margin-top: -100px;&quot;&gt; &lt;img alt=&quot;slider&quot; src=&quot;slider.jpg&quot; /&gt; &lt;/div&gt;</pre> <p>The slider div will get rendered after the map div and the negative margin will draw on top of the map div. You would have to adjust the margin-top value accordingly to whatever adjustment you would need.</p> 2007-10-08T21:18:58-04:001946476http://forums.asp.net/p/1167640/1946476.aspx/1?Re+DIV+on+top+of+another+DIV+without+absolute+positioning+Re: DIV on top of another DIV without absolute positioning ?! <p>&nbsp;Works like a Charm :) Thanks jamezw.</p> <p><b>&nbsp;Thank you guys for all your support. This forum rocks !!</b><br> &nbsp;</p> 2007-10-08T21:31:43-04:00