Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Float A Div

Featured Replies

hey all,

 

Is it possible to float a div, inside a div that contains an image?

 

<div id="content">

 

<img src="images/bg_02.png" alt="" width="960" height="499" /> (This image is to have hotspots, which is why I haven't got it as a background image)

 

</div>

 

I need some text to appear over part of the image....

 

Thanks

Gecko

As they say in Mexico "todo es posible!"

 

You may need to play with the z-index and position to get it where you want it, but yes you can do that no probs.

How about an image map?

If you have Dreamweaver it's dead easy to generate - you basically just draw out your hotspots and it'll create the links for you.

 

If you're wanting to put text over the image then you could still have the image as a background image, and then absolutely position divs over it...

 


<div id="my-image">
<ul>
<li class="hotspot-1">Hotspot 1</li>
<li class="hotspot-2">Hotspot 2</li>
</ul>
</div>

 

#my-image { background:url(images/myimage.jpg); width:500px; height:500px; position:relative; }
#my-image ul { margin:0; padding:0; }
#my-image ul li { list-style:none; display:block; position:absolute; }
#my-image ul li.hotspot-1 { width:10px; height:20px; top:10px; left:25px; }
#my-image ul li.hotspot-2 { width:15px; height:10px; top:40px; left:125px; }

 

And if you only want your hotspots to show when you've hovered over them

#my-image ul li { display:none; }
#my-image ul li:hover { display:block; }

 

Ideally, if your hotspots contain links then it's better, because you're not relying the :hover pseudo-selector on the <li> and you can apply the styles to the <a> tag instead...

 


<div id="my-image">
<ul>
<li class="hotspot-1"><a href="#hotspot-1">Hotspot 1</a></li>
<li class="hotspot-2"><a href="#hotspot-2">Hotspot 2</a></li>
</ul>
</div>

 

#my-image { background:url(images/myimage.jpg); width:500px; height:500px; position:relative; }
#my-image ul { margin:0; padding:0; }
#my-image ul li { list-style:none; }
#my-image ul li a { display:none; position:absolute; }
#my-image ul li a:hover { display:block; }
#my-image ul li.hotspot-1 a { width:10px; height:20px; top:10px; left:25px; }
#my-image ul li.hotspot-2 a { width:15px; height:10px; top:40px; left:125px; }

 

Or you can add a bit of jQuery to make things a little easier and cross-browser compatible (with the reliance on jQuery)...

#my-image { background:url(images/myimage.jpg); width:500px; height:500px; position:relative; }
#my-image ul { margin:0; padding:0; }
#my-image ul li { list-style:none; display:none; position:absolute; }
#my-image ul li:hover,
#my-image ul li.hover { display:block; }
#my-image ul li.hotspot-1 { width:10px; height:20px; top:10px; left:25px; }
#my-image ul li.hotspot-2 { width:15px; height:10px; top:40px; left:125px; }

 

$(document).ready(function) {
$('#my-image ul li').hover(function() {  }
$(this).addClass('hover');
, function() { //on blur
$(this).removeClass('hover');
});
});

 

I've written the code in this box so it's untested and might have a couple of typos, but it gives you the right idea. If you can't get it working let me know!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.