views:

27

answers:

1

I need to put some text over a series of images in a gallery. I found many tutorials about the text part however the images need to be floated. Whenever I add float:left though the trick no longer works. My code (css inline for sack of brevity):

<a href="/photos/photo1.php" title="photo1">
<span style="position: relative; width: 100%;">
  <img src="/photos/photo1.jpg" alt="" />
  <span style="position: absolute; top: 10px; left: 0; width: 100%;">Text over image</span>
</span>
</a>

<a href="/photos/photo2.php" title="photo2">
<span style="position: relative; width: 100%;">
  <img src="/photos/photo2.jpg" alt="" />
  <span style="position: absolute; top: 10px; left: 0; width: 100%;">Text over image</span>
</span>
</a>

This way the images are one under another but like I said I need to float them without breaking everything else.

+2  A: 

You will want to float the entire outer <span> or the <a>. My guess is that you are currently trying to float the <img> specifically, which causes the elements to end up in unexpected positions. If this assumption is incorrect, you might want to update with more details.

Jørn Schou-Rode
Misread the code, so deleting my answer below - if floating the span or a, then would they also need to mark it as display:block?
Michael
@Michael: There is no need to specify `display:block` explicitly, as all all browsers (AFAIK) sets this property implicitly when the `float` property is set.
Jørn Schou-Rode