Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

200
Visualizações
Moving outer div to center inner div

I'm pretty new at JavaScript, jQuery, and CSS.

I'm trying to change the position of the entire outer div so that the selected inner div will be centered in the screen without changing it's position within the outer div. I am using jQuery, but all the different options of widths, heigths, scrolls and offsets confuse me.. I'm not sure what I need to use and how.

I found this solution but it wasn't working for me:

var newX = ($outer.outerWidth(true) / 2) - ($inner.offset().left - $outer.offset().left) - ($inner.outerWidth(true) / 2);
var newY = ($outer.outerHeight(true) / 2) - ($inner.offset().top - $outer.offset().top) - ($inner.outerHeight(true) / 2);
$outer.css('transform', 'matrix(1, 0, 0, 1, ' + newX + ', ' + newY + ')');

P.S.: I'm not sure if it matters, but my outer div has massive padding. I'm pretty sure the 'outerWidth/Height' is supposed to count for that, but maybe it's one of the things that messes things up..

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda