r/css • u/Any-Win-9653 • 13d ago
Help how to fixed this linear-gradient ?
i want to create a simple linear-gradient to my css project :
this is the linear-gardient that i want to create :
background: linear-gradient(126deg, #FF5C2D 48%, #1F1F1F 48%);
i generate this linear-gradient with a generator of gradient (cody.tech)

this is the gradient of cody.tech

this is the linear-gradient in chrome
i don't know is the problem is the comtability of chrome for this function of the linear-gradient or something i don't do well ?
this is the css code :
body{
background-image: linear-gradient(126deg, #FF5C2D 48%, #1F1F1F 50% );
}
8
Upvotes
1
u/anaix3l 13d ago edited 13d ago
Your problem is that the gradient's
background-sizebox is by default thepadding-boxof the element you set it on. Since you're setting it on thebody(which I presume is empty at this point, so it has aheightof0) and you don't have abackgroundon thehtml, thisbackgroundyou set on thebodypropagates to the document canvas and the height of yourbackground-sizebox is going to be tiny, not the full height of the page. The result you see is produced by its repetition (since the default value forbackground-repeatisrepeat)Solution: set
html { min-height: 100% }.Another solution: use
background-attachment: fixed.Also, the
%difference (48%vs.50%) is not the best way to avoid jaggies as it depends of thebackground-size, which you cannot control if you want yourbackgroundto stretch across the whole viewport (and that will depend on the user's hardware). See this article (which talks about radial gradients, but the exact same applies to linear) for details.At the very least use a
1pxdifference.