Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 691

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 62k
Author
Asked: November 25, 20242024-11-25T01:14:08+00:00 2024-11-25T01:14:08+00:00

A responsive striped CSS gradient inspired by 80s VHS tapes

  • 62k

I'm really into retro-tech at the moment. And whilst I still haven't gotten round to playing with my new Commodore 64 Emulator, I have been collecting images of old VHS tapes that inspired the design of my most recent website project. Just look at the beauty that is the Sony T-120!

Front and back sleeve covers of the Sony T-120 Dynamicron VHS tape.

Inspired by the Sony T-120 and other similar retro VHS designs by Christopher Kirk-Nielsen (four of which are hanging proudly in my office!), I created a moodboard and sent it on to my good friend, designer and live streamer aaoa_. He created this beautiful retro striped pattern for me, and my challenge was to build this in pure CSS without using a background image.

Gradient horizontal striped background using hard stops, ranging from yellow at the top, through to orange, red, pink, purple, dark blue and bright blue.

How it looks

How it works

Hard stops

The pattern is created using a CSS linear-gradient (using the direction “to bottom”) with what are known as “hard stops“. A hard stop is created by defining the end of one colour in the same place as the start of the next colour.

vh units

The biggest design challenge was making sure the full pattern of 14 colours was visible at any viewport size, and didn't scroll with the content. The key was to use vh unit to determine the size of each colour stop. The vh unit is a relative unit, and describes a percentage of the viewport height. 1vh is 1% of the viewport height, 50vh is 50% of the viewport height and so on. Using vh is what enables the full gradient pattern to respond to the height of the viewport. Read more about different units in CSS on MDN.

Here's a two-colour hard stop gradient as an example, in which we're using the vh unit to specify the size of each colour stop.

  .twoColorStop {   min-height: 100vh;   background: linear-gradient(     to bottom,      red 0 50vh,     yellow 50vh 100vh   ); }   
Enter fullscreen mode Exit fullscreen mode

Here's the result.

A red block on top of a yellow block. Each block is the same size.

Notice that:

  • the first colour (red) ends at 50vh
  • the second colour (yellow) starts at 50vh

Where red stops, yellow begins, creating a hard stop. There are ways you can write the CSS above in a shorthand form, but I've written it out verbosely to demonstrate the concept more clearly.

The only differences between this example and the full example is that I'm using 14 colours instead of two colours, and I'm using CSS custom properties and CSS calc() to avoid writing out 14 lines of magic numbers. Notice though, that where one colour ends, another colour begins at the same vh value.

Screenshot of the CSS code using custom properties, showing that the end stop of the second colour is the same as the start stop of the third colour.

🔥 Today I learned!

Oliver Turner turned up on Mastodon with some solid advice that I'd not discovered before!

One interesting property of linear gradients that can make generating stripes less verbose is that any number less than the previous stop works to create a hard border, so instead of needing to track the previous value you can use 0.

Here's the demo

Thanks, Oliver!

And finally, to allow the page content to scroll whilst the background pattern stays fixed in place in the viewport, it's wrapped in a vertically-scrollable element inside the container providing the background gradient pattern. Set height: 100vh on this element to prevent the content increasing the height of the last colour in the gradient. Experiment in the CodePen above and see what happens if you remove the height property on the .wrapper class!

See what you can make with this CodePen. Take it, fork it, copy and paste it… Take this linear gradient wherever your heart desires!

beginnerscsstutorialwebdev
  • 0 0 Answers
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.