CSS Margin Negative without Moving Parent Container

不想你离开。 提交于 2019-12-06 08:44:52

问题


I am trying to get on this page (http://musicaladvocacy.org/) the area where it says "Home" (The White Container in the grey gradient) to go ~60 px up, but as you can see it does that as well as moves the parent container up. I just want the white box to move up NOT the whole thing. So it should look like this: http://musicaladvocacy.org/index-margin.jpg

Thanks for any ideas!


回答1:


You can apply position:relative; top:-60px; on the element you need to shift up.

#el {
   position:relative;
   top:-60px;
   z-index: 5;
}



回答2:


You could also add 1px padding to the top of the parent, and continue using negative margins.

.width { padding-top: 1px; }
.content { margin-top: -60px; }

This works because margins that are immediately up against one another combine into a single margin.




回答3:


What you are searching for is the css properties "position" and "top".

#div-1 {
  position:relative;
  top:-60px;
}

See step 2 on this guide. Many other websites have more information about this properties too.



来源:https://stackoverflow.com/questions/3217262/css-margin-negative-without-moving-parent-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!