Log in

View Full Version : HTML help


The Ninja
November 28th, 2010, 06:29 PM
I was wondering what the code for a floating image or text. Im not sure if floating is the correct term but basically what i mean by it is an image, picture, or possibly an adsense ad that stays in one place when scrolling rather than sliding off the page. Thanks in advance.

plus 1 rep. to anyone who gives me a freaking answer.

Commander Thor
November 28th, 2010, 11:13 PM
This isn't possible with straight up HTML (Though I haven't refreshed my skills for HTML5, so it may be possible now), you'll need to use some CSS as well.

The basic code looks like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>

<style type="text/css">
p.pos_fixed <!-- this states the name of the CSS element, and where it will be used (In <p>) -->
{
position:fixed;
top:30px;
right:5px;
<!-- these 3 lines state that it will be at a fixed position, 30px from the top of the browser window, and 5px from the right of the window -->
}

</style>
</head>
<body>

<p class="pos_fixed">
<img>http://www.image.com/image.jpg</img></p> <!-- this image will not scroll with the page -->
<p>Some text</p><!-- this text will scroll with the page -->
</body>
</html>


As a note; the <!DOCTYPE> /HAS/ to be declared in order for this to work in Internet Explorer. It doesn't have to be what I have up there, but you have to declare a doctype.
Also, if you're going to copy the code I supplied, remove the HTML comments from the CSS section, as I'm not sure if HTML comments can be used in the CSS section, or if it will cause errors.

The Ninja
November 29th, 2010, 09:41 PM
Is it possible to do this with out editing whats in between <head> </head> because my webhost provider doesnt allow me to edit that.

p.s. I'll still gave you the rep. if you cant help me any further (infact i have already)

Commander Thor
November 29th, 2010, 10:09 PM
Is it possible to do this with out editing whats in between <head> </head> because my webhost provider doesnt allow me to edit that.

p.s. I'll still gave you the rep. if you cant help me any further (infact i have already)

I'm not sure as I've never used the <style> tag out side of <head>, but it's worth a try I suppose.
The worst that can happen is it can slow the time it takes to load the page, as most browsers expect the CSS to be declared within the <head> tag. If it finds CSS outside of the <head> tag, the browser has to re-draw the webpage.
Edit: Actually, I take that back, the worst that can happen is it doesn't work. :p