views:

418

answers:

3

I'm attempting to display a logo (PNG created in Paint.NET) on my web page (XHTML 1.0 Transitional), like this:

<body>
  <div class="header">
    <div class="logo">
      <img src="logo.png" />
    </div>
  <!-- etc. -->

.header is styled as follows:

.header {
  background-color: Black;
  color: White;
  margin-left: -3em;
  padding-top: 12px;
  padding-left: 2em;
  padding-bottom: 12px;
  font-size: 1.4em;
}

.header .logo {
  float: right;
}

The logo is white-on-black, with some other colours.

On IE8 (and Google Chrome), the image is displayed correctly. On IE7, the image is not displayed at all. What am I doing wrong?

I don't care about IE6.

A: 

HTML or XHTML? Don't think that a self-closing img-tag is valid in HTML.

EDIT: You are also missing the alt-attribute.

dalle
XHTML 1.0 Transitional; updated question.
Roger Lipscombe
It's a logo; it has no vision-impaired equivalent. Do I still need an alt-attribute?
Roger Lipscombe
+1  A: 

If you drag-drop the image directly into IE7 does it display correctly?

If it does, then the issue isn't with the image but it's with your HTML or the CSS.

I don't have IE7 here so can't test directly, but I can recommend a simple approach to troubleshooting:

  • Remove the CSS styles one-by-one until the image renders in all of your target browsers. That should tell you what is causing the issue (hopefully the reason why will then be relatively easy to fathom)
Richard Ev
See update and comments on original question.
Roger Lipscombe
A: 

If it is the float:right that messes it up perheps you should try to clear your floats. Try setting overflow:hidden; on .header class, or apply clear:both on the element that follows it in the markup.

Also the img tag always requires the alt attribute - you can however leave it blank - alt=""

easwee
`overflow: hidden` makes it work. Care to explain why?
Roger Lipscombe
By setting th attribute overflow:hidden; on the container div you somehow remid it that it is wrapping the element inside it and it somehow clear itself. I believe it is considered as a CSS bug but works in all browsers. You can also clear it with :auto or :scroll properties and sometimes you will need to set width too (100% usually does it). Just watch out, to not use this to clear a div containing dropdown menus, or with ay other situations where content is offset out of the container, since it will cut it at the edge.
easwee