Nov 21, 2009

Relative Position (css)

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Designing > Web Design and HTML

Relative Position (css)

khalilov
I am making a coordinate system
CODE
p.map
{ position:absolute;
left:20%;
top:20%;
width:70%;
height:70%;
background-image: url(grass.jpg);
    background-repeat: repeat; }


An object(another image) appears in a certain position depending on GET vars
CODE
<p class="map"><?php
$x=$_GET['x'];$y=$_GET['y'];
$x*=74;
$y*=57;
echo "<div style='position:absolute;top:".$y."px;
left:".$x."px;'><img src='file:\\C:\wamp\www\Game\pic\mark.jpg'></div>";
?></p>


The position of the pic comes outside the map, whats the code so that that style coordination is relative to map, meaning 0px,0px are at top left of map box.

 

 

 


Comment/Reply (w/o sign-up)

pyost
When using absolute positioning (what you used for p.map), you are giving an element the exact position where it should be, relative to the whole page. If you, however, want to position an element relative to another element, the latter has to have position:relative as an attribute.

So, in your case, p.map would have position:relative (unfortunately, you would have to deal with positioning that element differently, I think), and the rest would stay the same.

Comment/Reply (w/o sign-up)

khalilov
I set the positioning to relative on both map and div, its different now. However the 0,0 are not at the top left of map box, i a had to
CODE
$x+=210;
$y-=270;

So that they are almost at the begining. Where is 0px,0px of map?

Comment/Reply (w/o sign-up)

Quatrux
I don't want to be wrong, but for example 0,0 will be in a position you are currently using top left, for example you are in the middle of a page and before you, you've got lots of elements, so 0,0 will be the currently most left position you can get and it's not like you always are linking to the top left of the page, you're linking to the top left of the current element and when you're using -1 or -20 coordinates, you overflow, I mean you get outside that element in the direction you're using.. I think it works like that tongue.gif

here is some source for it, also it has a testing tool, try it yourself tools:

http://www.w3schools.com/Css/pr_class_position.asp

Comment/Reply (w/o sign-up)

pyost
QUOTE(khalilov @ Dec 13 2008, 09:33 AM) *
I set the positioning to relative on both map and div, its different now. However the 0,0 are not at the top left of map box, i a had to
CODE
$x+=210;
$y-=270;

So that they are almost at the begining. Where is 0px,0px of map?


p.map should use relative, and the div should use absolute. When you use top:0; left:0, the top left corner of the div will be placed in the top left corner of the map - that's how it should work. If it isn't, then something else is the problem. Try posting the whole code wink.gif

Comment/Reply (w/o sign-up)

khalilov
It didn't work =), but this did:
CODE
<link rel="stylesheet" type="text/css" href="map.css" />
<p class="map">
<?php
$x=$_GET['x'];$y=$_GET['y'];
$x*=74;
$y*=57;
echo "<img style='position:relative;top:".$y."px;
left:".$x."px;'src='file:\\C:\wamp\www\Game\pic\mark.jpg'>";
?>
</p>

Turns out the <div></div> were messing things up. By putting the image directly inside <map> tags its 0,0 were set to top left of map. Then by using relative positioning it works. Thanks guys, especially for the relative position thing, didn't know it =). Alot of recoding to do O.o

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Relative Css


    Looking for Relative, Position, Css

See Also,

*SIMILAR VIDEOS*
Searching Video's for Relative, Position, Css
advertisement



Relative Position (css)

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com