How to center a div with auto width? [closed]

1

I have a div inside the footer, but it is expandable in width, how do I center it? I've already used margin: 0 auto; but it was not.

<footer class="rodape">
    <div class="centralizar"></div>
</div>
    
asked by anonymous 25.04.2016 / 22:20

2 answers

2

The problem of not centralizing the div is the problem that your 'rodape' class does not have a defined width, and the same goes for the 'centralize' div ...

.rodape{
  width:100%; 
  background:red
}
.centralizar{
  width:80%;
  background:gray;
  margin:0 auto;
  padding:20px
}
<footer class="rodape">
    <div class="centralizar">qualquer coisa aqui</div>
</div>
    
26.04.2016 / 06:43
1

If you want a div responsive to self-tuning and it remains centralized use the following css:

.centralizar{width:20%; margin: 0 auto;}

If you want to increase the div, just increase the width of the porce. Remember the position and relative html structure made.

    
26.04.2016 / 01:06