Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Responsive square, HOW ? 🤔, here's the solution !
Moulun Kevin
Moulun Kevin

Posted on

     

Responsive square, HOW ? 🤔, here's the solution !

The problem

I've always got some design ideas for galleries in a grid form, but it always required square cover, the only problem was that it wasn't really responsive if I was fixing a height and width in px, but doing the same with % em rem was a nightmare until now

the solution

Alt Text

The solution is quite simple when you think of it, if we take a div with a width in percentage then we apply a padded bottom on a:: after pseudo element,The padding is basing it’s width from the parent container, so when we set padding-bottom to 100%, it basically means 100% of its width, so with this you get a responsive square

I hope this post helped you with this struggle 👍

Top comments(2)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
mrkbr profile image
Mario Kober
  • Location
    Germany
  • Work
    Webdev at MK7
  • Joined

If you can use vw for width you can make it even simpler.
width 25vw
height 25vw

CollapseExpand
 
atndesign profile image
Moulun Kevin
Hi I'm Kevin but better know as ATNdesign, I like to share some knowledge with peopleFront end developper
  • Location
    France
  • Work
    Front end developper React JS at Nowhere yet
  • Joined

Oh yeah did not think of that, that is a good solution! Thanks for sharing it

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Hi I'm Kevin but better know as ATNdesign, I like to share some knowledge with peopleFront end developper
  • Location
    France
  • Work
    Front end developper React JS at Nowhere yet
  • Joined

More fromMoulun Kevin

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp