tags:

views:

26

answers:

3

Hello

I have a problem with headline tags when I float them around an image in compability-mode in explorer.

<img src="1.gif" style="float: left; margin-right: 10px"><h1>Some headline</h1>

The picture is like 100px high, and by default the text centers in middle, which it should, but with compability-mode on it aligns top.

How can I fix so it vertically aligns center?

/Molgan

A: 

It's not "pure CSS", but it is "IE-proof"!

<table>
  <tr>
    <td style="margin-right: 10px">
      <img src="1.gif">
    </td>
    <td valign="middle">
      <h1>Some headline</h1>
    </td>
  </tr>
</table>
Brad
Oh look, someone doesn't like `tables` and thinks they deserve an automatic down-vote. Well, I think **IE** deserves a few down-votes.
Brad
+4  A: 

Is there a specific need to float the H1 tag next to the image? Another alternative would be to assign the image as a background to the H1 tag, and then use css background-position and padding to position your text and image to display correctly. Can you provide your html markup or a link to the page?

h1 { background: url(/path/to/my_image) 10px 15px no-repeat; padding: 20px; }

That would put your image as the background of the H1, and position it 10px from the left and 15px from the top, for example.

Stephen Moran
+1 for the background-image suggestion
Brad
@Stephen Moran This is a nice solution, but you are limited to a certain size of the image.
Justus Romijn
@Justus, you're not limited to a particular **size** of image, you just can't ***scale*** it with this method. You are limited to the native resolution of the image.
Brad
@Brad I understand. But what the asker wants is an image next to the headline. So you can use padding/background, but then you need to know what the size of the image is to give the headline enough space to fit the image in.
Justus Romijn
@Justus, I see, so you're just pointing out that the positioning (`10px 15px`) of the background image and padding (`20px`) of the header is related to the dimensions of the image itself; fair 'nuf. So my solution, while not pretty and obviously not popular, is **very** effective.
Brad
@brad My point is that you should not have to use CSS when you are changing content. If there are multiple headlines with images, each headline should get a different class to change the values of the padding, otherwise the text would overlap the image. It is very **ineffective** that way.
Justus Romijn
@Justus, then everyone should rally behind my table-solution. :)
Brad
@brad I think i gave a nice, cross-browser and clean solution below, but this answer was already accepted :)
Justus Romijn
A: 

Why float the image? Save yourself some time and put the image in the headline tag, and then you can use vertical align to position it.

JsFiddle solution

Works cross-browser as far as I can check.

Justus Romijn