DEV Community

Hamza Nouali
Hamza Nouali

Posted on

CSS - Making child element responsive for its parent.

Hello everyone, I want to know if there is a way without JavaScript to make the children elements responsive corresponding to the parent element and not the window.

Top comments (4)

Collapse
 
ludamillion profile image
Luke Inglis

There have been proposals for such but nothing has ever made it very far. Search β€˜css container queries’ for something that seems like it has the most steam recently. Still not necessarily promising

Collapse
 
pclundaahl profile image
Patrick Charles-Lundaahl

I don't think so. Not without it being extremely hacky. If you find one, I'd be interested in seeing it!

Collapse
 
hamzanouali profile image
Hamza Nouali

For now, media queries are good enough to make things work and responsive 100% for all devices but because I am lazy, I am trying to make my code fit any container in any project without any extra work.
Till now, it looks impossible without JavaScript.

Collapse
 
roroland profile image
Roroland 🎹 πŸ’» - A.k.a. SonicByte

Maybe you can get that behavior with auto fit of css Grid......