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

157
Visualizações
Centered content with side panel via CSS

Thinking about this for a couple of days and still did not find a better solution than with JS. Maybe I have missed something. I have a dynamic layout like this:

--------------------WINDOW width---------------
######### ####################### #############
#       # #      content        # #           #
# left  # #                     # #   right   #
#       # #     ooooooooooo     # #           #
#       # #     o  BOX    o     # #           #
#       # #     ooooooooooo     # #           #
#       # #                     # #           #
######### ####################### #############

What I need to achieve is to have BOX centered with the window when it is possible:

  • If I am scaling window it is all the time centered.
  • left and right panels visibility can be toggled visible/hidden (with animation to the side)
  • If I hide the left panel and make windows smaller, then BOX should be centered if possible, but if not and the right panel would be overlapping the BOX I need to start shifting the BOX to the left. So the priority is centered BOX but if it is not possible then move it to the side.
----------WINDOW width---------
################# #############
#      content  # #           #
#               # #   right   #
#   ooooooooooo # #           #
#   o  BOX    o # #           #
#   ooooooooooo # #           #
#               # #           #
################# #############

BOX is some responsive content which width could be affected by window height (with aspect ratio)

Any idea without JS? I was thinking about FLEX and flex-shrink with little JS help, but was not able to achieve.

Solution with js is clear to me, that I will compute window width and side panels width and from that, I can compute the offset.

Here is the code what I have tried:

https://codesandbox.io/s/flamboyant-tamas-n6jwg?file=/src/App.js

I have added fake side panel. Left panel is not so important for me. This is somehow working, but still thinking if there is any better solution without the fake panel.

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