Jump to content

auto margin problem


robert_gsfame

Recommended Posts

Auto margins don't work when you have absolute positioning. They can't - the whole point of absolutely positioning an element is to make it absolutely be in that position no matter what.

 

Also, having an auto margin but keeping it in the same position as far as the left doesn't make sense. You either want it to center, or you want it to be where it is. It can't do both.

 

Let me give you some work that will save you a lot of work: Remove all the absolute positioning from your CSS, and spend a few hours learning how to position elements with floats. Absolute positioning is fools gold - looks nice but is mostly worthless.

Link to comment
Share on other sites

okay..so i have to use auto margin n put everything inside the table <table></table>, is that what you mean haku?

 

No, that's not what I meant at all. And actually, tables are even worse.

 

What I meant is what I said - spend a few hours/days learning to position using floats.

Link to comment
Share on other sites

I wouldn't take haku's advice on absolute positioning to seriously, its ungrounded. You just need to remember this basic rule of thumb, absolute positioning only works inside other elements, when their position is set to something else then static.

 

Centering elements using absolute positioning, can be done using percentages. Example follows.

 

<!DOCTYPE html>
<html lang="en-US">
  <head>
    <title>My first Website</title>
    <style type="text/css">
      #Basement {
        position: relative;
        margin: auto;
        width: 75%; /* The layout takes up this Percentage width, but can't be wider then max-width, and narrower then min-width. */
        min-width: 768px;
        max-width: 1600px;
      }
      #Main {
        position: absolute;
        left: 25%;
        width: 50%;
        background: #808080;
        min-height: 400px;
      }
    </style>
  </head>

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

</html>

 

In this case i set Basement to relative, to enable absolute positioning relatively to its specified boundaries, i then used left: 25%; Which is about half the width of Main, obviously this will center the element nicely.  ::)

Link to comment
Share on other sites

Oh it was grounded. We've had this argument before, and the only example you could show me was some crappy site design you did that had no elements overtop each other vertically.

 

Layouts that are positioned with Aboslute positioning don't work. Simple as that. Until you can show me one decent site anywhere that has been positioned absolutely, I can only say that you don't know what you are talking about.

Link to comment
Share on other sites

Oh it was grounded. We've had this argument before, and the only example you could show me was some crappy site design you did that had no elements overtop each other vertically.

 

Layouts that are positioned with Aboslute positioning don't work. Simple as that. Until you can show me one decent site anywhere that has been positioned absolutely, I can only say that you don't know what you are talking about.

You mean in this in This Thread ?

That's over a year ago, and you did actually view some of my layouts, the link posted by bronzemonkey, was in fact a collection of older Example layouts on my company Website, designed by me.

 

I thought we basically agreed back then, at least thats whats it looks like when i read some of your later posts in the thread, though it appears i was busy showing bronzemonkey that the coding required was about the same, which holds true for more complex layouts as well.

 

The only problem with AP, (as far as i know), is that you can't have a footer, which spans across all of the columns, and gets "pushed" accordingly by the longest column. But hay, far from all layouts includes a footer, and you can still include a footer in the center column, which is a fairly common design.

 

I would likely still use AP to some degree for footer layouts, while floating the contents of the main wrapper. I.e. Use AP for the Header and Footer, the rest can be accomplished with relative positioning and floats.

 

 

 

 

 

 

 

 

 

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.