Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!