redho home | products | services

Programming Forums


Community for Java, PHP, Perl C, ASP and Python programmers
Friday 03 September 2010 04:42

Ask your IT question here

position: relative/absolute



 
Post new topic   Reply to topic    Programming Forums -> CSS forum
View previous topic :: View next topic  
Author Message
linx
New Programmer


Joined: 09 Feb 2009
Posts: 11
People, I'd like to discuss problems of positioning blocks on web-pages.
I don't understand the difference till the end... Embarassed
_________________
...and justice for all...

Reply with quote
 
musician
Enthusiastic Coder


Joined: 09 Feb 2009
Posts: 27
Within CSS you can position where exactly items will appear in the browser. This is done by either one of two ways. An absolute position, whereas you are defining exactly where within the browser that the item should appear. A relative position, where an item is placed within the browser based on its relationship to another item already in the browser output.
Reply with quote
 
musician
Enthusiastic Coder


Joined: 09 Feb 2009
Posts: 27
Look, it is simple:
Code:
<html>
<title>CSS - Absolute / Relative Position</title>
<body>

<img id='img_abs">

</body>
</html>


in CSS:
Code:
#img_abs
{
position:absolute;
left:100px;
top:150px;
}
Very Happy
Reply with quote
 
max
Guest Programmer




Value Description
static
Default. An element with position: static always has the position the normal flow of the page gives it (a static element ignores any top, bottom, left, or right declarations)
relative
An element with position: relative moves an element relative to its normal position, so "left:20" adds 20 pixels to the element's LEFT position
absolute
An element with position: absolute is positioned at the specified coordinates relative to its containing block. The element's position is specified with the "left", "top", "right", and "bottom" properties
fixed
An element with position: fixed is positioned at the specified coordinates relative to the browser window. The element's position is specified with the "left", "top", "right", and "bottom" properties. The element remains at that position regardless of scrolling. Works in IE7 (strict mode)

Reply with quote
 
linx
New Programmer


Joined: 09 Feb 2009
Posts: 11
Thanks!
I should do a column where there will be background, on that background I need to put an image and on that image - text...
Embarassed
I hardly understand how to do that...
_________________
...and justice for all...

Reply with quote
 
musician
Enthusiastic Coder


Joined: 09 Feb 2009
Posts: 27
Try putting in a div background

Then you can put two div's one by another with absolute position

Reply with quote
 
musician
Enthusiastic Coder


Joined: 09 Feb 2009
Posts: 27
or relative and absolute...
Reply with quote
 
linx
New Programmer


Joined: 09 Feb 2009
Posts: 11
It works! Razz
Code:
#lftBar div.panelIMG {
   position:absolute;
   top:2px;
   left:2px
}
#lftBar div.panelTXT {
   position:absolute;
   top:0px;
   left:0

Now I have one more problem - in Opera 9.0 the text area is pushed from the right border by 5px as if I've put padding-right:5px... but I have
Code:
   margin:0;
   padding:0

any ideas?
_________________
...and justice for all...

Reply with quote
 
musician
Enthusiastic Coder


Joined: 09 Feb 2009
Posts: 27
try hack for Opera...
Reply with quote
 
linx
New Programmer


Joined: 09 Feb 2009
Posts: 11
I've resolved that problem... Helped fixed width:
Code:
#lftBar div.panelTXT2 {
   position:absolute;
   top:0;
   left:0;
   width:215px

_________________
...and justice for all...

Reply with quote
 
Page 1 of 1
Post new topic   Reply to topic    Programming Forums -> CSS forum


Dubai Forums - Expat Help | Vegan Forum | Java Programming | 3d Design Resources | 3d Forum | 3D Jobs | 3D Textures | Paris Forum | Europe Forum
Dubai Classifieds | Dubai Property | Jobs in Dubai | Free London Classifieds | Jobs in London UK

High Quality, Custom 3d animation and Web Design solutions Royal Quality Web Hosting Services Vegetarian and Animal Rights news

Based on phpBB © 2001-2010 RedHo