Jump to content

Do You Position Elements with the Position Property or with Margin and Padding?


Fluoresce

Recommended Posts

OK well i just learnt, Never use padding and or margins to form your site layout because it is really buggy in IE, to get around this you can use a container element to store all your other elements in, just set a fixed width and height for the container element and the rest of the elements should be fine going off margins and padding.

 

Keeping in mind I'm still in the early stages of learning this css stuff:)

Link to comment
Share on other sites

To be safe you can avoid using padding on containing elements and set margins on the child elements.  For example if you have a sidebar set to 200px wide, you probably don't want to set your padding on the sidebar container, but set margins on the child elements like p, ul, h1-h5, etc.  This is a safe way to avoid box model problems.

Link to comment
Share on other sites

If you want a border around all the child elements, but inside the containing div, then you can do this:

 

<div style="width:200px">

  <div style="margin:20px; border:solid black 1px;">

    <h1 style="margin:0 10px">H1</h1>

    <p style="margin:10px;">paragraph</p>

  </div>

</div>

 

(note: I put the styles inline just for visual representation. They shouldn't actually be put inside the HTML tags like that.)

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.