How do I eliminate the top space my DIV leaves?

Asked

Viewed 3,680 times

2

I have a DIV of leaves a space between her and the top of the browser, see: http://www.roteirodoimovel.com.br/modelos/3/teste.php

CSS:

    .element {
position:relative;
display: table;
width:960px;
height:120px;
margin: 0 auto;
padding:0px;
background-color:#000000;
border:0px;
    }

I tried several things but without success. I need my DIV stick to the top of the browser.

  • 1

    Check if you have margin or padding in the element that contains that div. If you don’t, go up the hierarchy until you find the culprit. It is quite possible that the margins are "collapsing".

3 answers

4


You can use the following css:

* {
margin: 0;
padding: 0;}
  • margin: 0 auto; is to leave my div centralized

  • 3

    Change the selector from * to body then, and try again. The selector '*' means that it will assign all elements.

  • Beautiful boy, it worked right. Thank you very much!

  • Glad to hear it!

0

Try to edit to:

.element{
  position:fixed;
  padding-top: 0px;
  margin-top: 0px;
}
  • Didn’t work..

  • @Gladion Neuza Perosini Try now I edited my answer.

0

Try:

.element {
  margin-top: -20px;
  position: absolute;
  display: table;
  width: 960px;
  height: 120px;
  background-color: #000000;
  border: 0px;
}

Explanation:

This happens because the whole element has a space of 20px with the top of the browser, and no use you put 0px, because there is a space of 20px between the div and the top of the browser.

I hope I’ve helped :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.