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.

Trying to position fixed an image in Internet Explorer

Featured Replies

Hi

 

I am trying to position fixed some image on my site however it doesn't show correctly in I.E.

 

My current code is:

 

<img src="image.jpg"; style="position:fixed; right:20px; top:200px"/>

 

 

How can I make this work in IE?

How exactly is IE showing it?

IE6 doesn't understand position:fixed, but I believe later versions do (someone may correct me though).

  • Author

IE just puts the element on the top left corner of the page.

I don't have my website online yet to give a link.

So I can't do the effect I want in IE?

try removing the ; after "image.jpg"

  • Author

Hi thanks for the responces.

 

It is IE version 8.

 

After you told me that for you it works, I tried it again with just that code and it worked. But when I put in my other content it doesn't. By removing elements one by one I found this to be causing the problem:

 

<!--===================-->
<!--Copyright (c) 2010 -->
<!--===================-->

 

As I'm sure you understand I added this to show that it's copyright content.

 

I added it on the far top of the page before anything else -before the DOCTYPE and the <head> stuff.

But if it's causing trouble that means that's not the right place to put that.

So where should I put it?

 

thanks

  • Author

Also, in regards to the fact that fixed positioning does not work for IE 6 and downwards, I wanted to ask if there's a way to make this image get position absolute when in these browsers (at the same place on the page). In other words to write a code that sais that in all browsers be position:fixed, while from IE6 and downwards be position:absolute.

 

Is there a way to do that? thansks

I added it on the far top of the page before anything else -before the DOCTYPE and the <head> stuff.

But if it's causing trouble that means that's not the right place to put that.

So where should I put it?

 

Don't ever put anything before the doctype. Put comments like that in the head section or the body section.

 

In other words to write a code that sais that in all browsers be position:fixed, while from IE6 and downwards be position:absolute

 

You may not need to do anything. IE6 won't process position: fixed; and usually just applies position: absolute. If you want to make sure, add in a conditional comment for IE6 right at the end of the head section, after any head section styles and links to stylesheets, but you will have to delete the position: fixed; from the inline style and add a id in the main stylesheet:-

 

Main stylesheet CSS:-

img#special { position:fixed; right:20px; top:200px; }

 

Code last in head section:-

<!--[if IE 6}>
<style type="text/css">
img#special { position: absolute; }
</style>
<![endif]-->

 

HTML markup with id but without inline style:-

<img id="special" src="image.jpg" alt="image description" />

 

You have to delete the inline style because it would be processed last and you don't want that, you want the main style processed first for all browsers and then the conditional comment just for IE6. The position: absolute should put the image in the same place, but it will scroll in IE6 instead of staying fixed in the window.

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.