Centralized Div

0

This my div is not in the middle of the screen, is the CSS style wrong?

<div style="position:absolute;margin:auto;">
    <img src="assets/img/PHP.png"/>
</div>
    
asked by anonymous 01.08.2017 / 21:02

1 answer

2

.div{
   width: 200px;
   height: 100px;
   background: black;
   margin: 0 auto;
}
<div class="div">
   <img src="test.jpg">
</div>

Here's an example.

After reading the above comments, follow the edit

.div{
  width: 100px;
  height: 100px;
  background: black;
  position: absolute;
  left: 50%;
  margin-left: -50px;
}
<div class="div">
    
  </div>

Updated example

.div{
      width: 100px;
      height: 100px;
      position: absolute;
      left: 50%;
      margin-left: -50px;
      bottom: 30px;
      z-index: 99999999
    }
    
footer{
      width: 100%;
      height: 50px;
      background: black;
      margin-top: 200px;
      bottom: 0;
      position: absolute;
}
<div class="div">
  <img src="https://forum.imasters.com.br/uploads/monthly_2017_02/mascote.png">
</div>

<footer>

</footer>
    
01.08.2017 / 21:11