Jump to content

Positioning Help


eleven0

Recommended Posts

I use

 

position:absolute;
top: 120px;
left:24%;

 

It works fine, I have set my div as i wanted but when you resize your browser, div moves around too(positions itself with those values within the resized browser). Is there a way for me to stick that div at that place. I don't want it to move as you resize your browser.

 

I chose position:absolute because it's really easy for me to put whatever i want wherever i want, but everything gets messed up when you resize your browser. Any alternative ways or ideas?

Link to comment
Share on other sites

Dont absolutely or relatively position your divs. Look in to other methods such as floats.

 

What type of layout are you trying to achive?

 

Why would you not want to relatively position your divs? As I understand it, relatively position divs is just as beneficial as floating a div.

Link to comment
Share on other sites

absolute positioning is awesome - provided you know what you're doing...

 

the reason your div moves around is because your absolute positioning is doing exactly what it should.

 

left:24%; will change (as in 24% of a smaller value) once the parent containers width has changed...

Link to comment
Share on other sites

ToonMariner is right, absolute positioning is awesome, once you know what you are doing.

 

The trick is that you must position the parent element to have it behave as generally wanted. A lot of beginners quickly abandon absolute positioning when they experience what you did.

 

Above would usually mean to apply position: relative; to the parant. Below is an example of how to do this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="eng">

  <head>
    <title>My first Website</title>
<style type="text/css">
    #Basement {
      position: relative;
      width: 700px;
      height: 700px;
    }
    #Content {
      position: absolute;
      top: 0;
      right: 0;
      width: 400px;
    }
    </style>
  </head>

  <body>

    <div id="Basement">
      <div id="Content">
        <p>My first Website.</p>
      </div>
    </div>
  </body>

</html>

 

See also: CSS Position Based Layouts

Note that the equal height-column layout has some outdated information, mainly regarding having a image or color fill out the canvas horizontally, this is something which there are working solutions for, i just haven't gotten around updating the Example yet. And i would also like to post an example at some point, this would mainly open up for a bottom for my underwater-layout.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.