How to center a div with auto width?

Asked

Viewed 398 times

1

I have a div inside the footer, but it is expandable in width, how do I center? I’ve used margin: 0 auto; but it wasn’t.

<footer class="rodape">
    <div class="centralizar"></div>
</div>
  • put an example there with the css of what you did

  • footer.rodape > aside.footer-down > . partners { width: auto; margin: auto; } this is the div I want to center on

  • footer.rodape > aside.footer-down { margin: auto; width: 950px; height: 50px; display: table; position: Absolute; bottom: 0px; } this is where the footer is

  • If it didn’t work with margin: 0 auto; is for some other issue on your page. If you don’t put the CSS in the question, it gets tricky for someone to answer.

  • In this case you can remove the question, or post the solution as an answer, if you think it might be useful for other people.

2 answers

2


Probably the problem of not centralizing the div is the question that its class 'rodape' does not have a defined width and the same goes for the div 'centralize'...

.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>

1

If you want a div responsive auto 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 portioning. Remember the position and relative to the html structure made.

Browser other questions tagged

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