1

I'm trying to generate a gradient background with linear-gradient in CSS. Here's an example codepen https://codepen.io/JSislife/pen/vYxrYEv. As you can see on the bottom right corner there is no transition of colors between orange and white; but the top left is the opposite. How do I make the top left not have a color transition as well?

2
  • 1
    like this ? background: linear-gradient(135deg, white 15%,#bd6430 15% 70%, white 70%) fixed; ? Commented Jun 6, 2021 at 23:01
  • @G-Cyrillus Thanks, that worked. Can you explain why there are 2 defined percentages here #bd6430 15% 70% ? Edit: nevermind, I see that you started the color at 15% of the width to match the first color placement Commented Jun 6, 2021 at 23:02

1 Answer 1

2

Just as @G-Cyrillus mentioned in the comments, if you add color stops to your linear-gradient you can create gradient sections that don't fade into eachother but have defined start/stop positions.

body {
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, white 0% 15%, #bd6430 15% 70%, white 70%) fixed;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test</title>
</head>
<body>
    <div id='home'></div>
</body>
</html>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.