LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-12-2023, 10:59 AM   #1
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,587

Rep: Reputation: 179Reputation: 179
CSS background-color gradient


I'm trying to create a background gradient on my wepage. I've tried (in .css):
Code:
body { background-image: linear-gradient(top left to bottom right, rgb(105,153,255), rgb(226,250,255)) }
The above does nothing. Other permutations I've tried (I won't them them all) give me bands of gradients, about 4 bands vertically with gradients from left to right (e.g. using "to bottom right").

I'm using Microsoft Edge 117.0.

What is the correct syntax for a gradient starting at the upper left and going to the bottom right?

Last edited by mfoley; 10-12-2023 at 11:00 AM.
 
Old 10-12-2023, 01:45 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
Quote:
Originally Posted by mfoley View Post
I'm trying to create a background gradient on my wepage. I've tried (in .css):
Code:
body { background-image: linear-gradient(top left to bottom right, rgb(105,153,255), rgb(226,250,255)) }
The above does nothing. Other permutations I've tried (I won't them them all) give me bands of gradients, about 4 bands vertically with gradients from left to right (e.g. using "to bottom right").

I'm using Microsoft Edge 117.0.

What is the correct syntax for a gradient starting at the upper left and going to the bottom right?
Try this (from quick look at The Book of CSS3 from NoStarch Press):

Code:
body { background-image: linear-gradient(to right bottom, rgb(105,153,255), rgb(226,250,255)) }
I am fortunate enough to have never experienced the edgy browser so no idea if it uses some other syntax, although the book indicates this should work from IE10.

Last edited by astrogeek; 10-12-2023 at 02:16 PM. Reason: bottom right -> right bottom per examples
 
Old 10-13-2023, 05:55 PM   #3
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,587

Original Poster
Rep: Reputation: 179Reputation: 179
Amazing! That worked. That was a simple combination I didn't try. Thanks!
 
Old 10-19-2023, 09:20 AM   #4
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,587

Original Poster
Rep: Reputation: 179Reputation: 179
Actually, that didn't work. I must have had a table or DIV that took up much of the screen and I thought it was working. I still get bands of gradient. See attached. The stripped-down html is:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<title>test Gradient</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
body { margin: 0; background-image: linear-gradient(to right bottom, rgb(105,153,255), rgb(226,250,255)) }
</style>
</head>
<body style="font-family: 'Trebuchet MS', Arial; margin-top: 20px">
<div style="text-align: center">October 19, 2023 10:00 AM</div>
</body>
</html>
It shows this way on both Firefox and Edge.
Attached Thumbnails
Click image for larger version

Name:	gradient.jpg
Views:	7
Size:	19.7 KB
ID:	41880  
 
Old 10-20-2023, 11:44 AM   #5
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,587

Original Poster
Rep: Reputation: 179Reputation: 179
I take it background-image: linear-gradient() simply doesn't work other than "to right" or "to left". Any vertical or diagonal gradients band, as shown in my previous post. For example, I have this simple html:
Code:
<!DOCTYPE html>
<html lang="en">
<body style="background-image: linear-gradient(rgb(105,153,255), rgb(226,250,255)">         
Hello World!
</body>
</html>
This is takes the default direction of "Top to Bottom". It bands. So does "to bottom right". This happens on Linux Firefox 115.3.1esr, Windows Firefox 118.0.1 and Windows Edge 118.0.2088.46.

So, for directions other than "to right" or "to left" linear-gradient() just doesn't work in these browsers, agreed?
 
Old 10-20-2023, 10:11 PM   #6
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,736

Rep: Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213
My go-to for css, among other things, is w3schools
https://www.w3schools.com/colors/colors_gradient.asp
Sometimes I learn. Sometimes I just setup things as i want them to be and copy/paste the resulting code. Their “Try it yourself” editor is very useful.

Edit: just finished reading mfoley’s post. Not using Firefox at the moment. I’m typing on glass in Safari. Check out that link on Firefox. (I’ll try it later…)

Later -- This code:
Code:
<!DOCTYPE html>
<html>
<style>
div {
    height: 800px;
    background: linear-gradient(to bottom, #0000ff 0%, #99ccff 100%)
}
</style>
<body>

<div></div>

</body>
</html>
Works as it should in Firefox 118.0.2

Last edited by scasey; 10-21-2023 at 03:06 AM.
 
Old 10-26-2023, 12:04 AM   #7
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,587

Original Poster
Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by scasey View Post
My go-to for css, among other things, is w3schools
https://www.w3schools.com/colors/colors_gradient.asp
Sometimes I learn. Sometimes I just setup things as i want them to be and copy/paste the resulting code. Their “Try it yourself” editor is very useful.

Edit: just finished reading mfoley’s post. Not using Firefox at the moment. I’m typing on glass in Safari. Check out that link on Firefox. (I’ll try it later…)

Later -- This code:
Code:
    background: linear-gradient(to bottom, #0000ff 0%, #99ccff 100%)
Works as it should in Firefox 118.0.2
My target browser for this application is Edge. "to bottom" bands. In fact, it also bands on Firefox 118.0.2 on my Windows computer. "to right" seems to give the best results.
 
  


Reply

Tags
css, gradient, html



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Screen App, Retain BG Color, Background color gets lost duerra Linux - Software 1 07-08-2009 03:01 PM
Choppy Color Gradient with Nvidia Drivers and 8 Series Card aligoodn Linux - Hardware 1 07-15-2008 10:01 AM
removing text shadows in kde; removing taskbar color gradient webazoid Linux - Software 1 04-11-2006 02:56 AM
Setting Background color using CSS patpawlowski Programming 3 02-25-2004 01:27 PM
bsetroot -gradient texture -from color -to color patpawlowski Linux - General 3 02-10-2004 01:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration