DEV Community

Jean Tiston
Jean Tiston

Posted on

2 1

When should I use percent/vh/vw and fixed pixel sizes?

A bit of a background on why I am asking this. So I was doing a frontend coding challenge at Frontend Mentor that is a Testimonial Page Slider. So mainly it has a portrait image and a testimonial quote.

Desktop screenshot of testimonial slider

Besides using breakpoints, I tried to make my design more responsive by using percent/vh/vw in some of the sizes. One example of that is for the size of the main image:

.photo {
    width: 70vw;
    height: auto;
    border-radius: 10px;
    box-shadow: 20px 20px 50px rgba(0,0,0,0.3);
}

and the slider arrow navigation which is supposed to be positioned at the bottom part of the image:

.nav {
    display: float;
    position: absolute;
    left: 40%;
    top: 85%;
    padding: 13px 10px;
    background-color: white;
    border-radius: 50px;
    box-shadow: 20px 20px 50px rgba(0,0,0,0.3);
    cursor: pointer;

}

But as one of the feedback I have gotten pointed out, the text and image proportion is not very good when it gets at 460px to 600px. The slider arrow navigation also gets displaced at some point.

Screencap of breaking layout

She suggested that I just use a fixed size for the image and I think that's true in this case.

So back to the question: **when do I know that it's better to use percent/vw/vh in my design and when to use fixed pixel sizes?

Can I also use percent/vh/vw for font sizes? And if yes, does it make sense to do so? And when, if ever, should I do that?**

If you want to scrutinize the page further here is the live site. If you want to see the code you can probably just inspect the page but in case you want the repo here it is.

I'm quite new with this frontend thing and so I'd really appreciate if you'd point me to a few resources I can refer to when I have these kind of questions.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay