Differences between margin-top and top

Whether you're a budding designer looking for some tips or a HTML guru looking to advise, the Website Design & Graphics forums are the perfect place for you. Want your site reviewed? Post it here for our members and moderators to critique.
Post Reply
silvestri
Newbie
Posts: 2
Joined: Mon Oct 02, 2017 9:37 am

Mon Oct 02, 2017 9:39 am

I'm learning CSS and I doubted the differences, well I'm designing a page with css but use margin-top and then change it to top and there was no change, then I do not know when to use u when using the other.


User avatar
capitalist
Junior Member
Posts: 15
Joined: Fri Oct 10, 2014 4:33 am

Mon Oct 02, 2017 9:43 am

margin top is absolutely on the margin against the top element. that is, it is as if you create a div there to fill

top is a positioner, that is, it places the element in a position, this is not part of the element (such as the properties that affect the margin)

usually behave very similar, but in the presence of the attribute position, top will have different behaviors than margin
silvestri
Newbie
Posts: 2
Joined: Mon Oct 02, 2017 9:37 am

Mon Oct 02, 2017 9:48 am

So for example I was designing a page to practice and use pure margin-left and margin-top, it would have been better to use the top and left to position
User avatar
capitalist
Junior Member
Posts: 15
Joined: Fri Oct 10, 2014 4:33 am

Mon Oct 02, 2017 9:50 am

no, it is usually better to maintain margin than positioning, positioning can disagree on responsive, margin is more solid in that aspect, usually top and left is used with position when it is absolute or fixed.
User avatar
Daniel204
Newbie
Posts: 5
Joined: Tue Jun 19, 2018 4:42 pm
Location: London

Tue Jun 19, 2018 4:49 pm

Hi,

You'd use margin, if you wanted to move a (block) element away from other elements in the document flow. That means it'd push the following elements away / further down. Be aware that vertical margins of adjacent elements collapse.

If you wanted the element to have no effect on the surrounding elements, you'd use positioning (abs., rel.) and the top, bottom, left and right settings.

With relative positioning, the element will still occupy its original space as when positioned statically. That's why nothing happens, if you just switch from static to relative position. From there, you may then shove it across the surrounding elements.

With absolute positioning, you completely remove the element from the (static) document flow, so it will free up the space it occupied. You may then position it freely - but relative to the next best non-statically positioned element wrapped around it. If there is none, it'll be anchored to the whole page.

Regards,
TechTIQ Solutions
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 0 guests