Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda