I am in the process of learning HTML.
What is the best way to create a gradient background for an HTML page?
So far this is what I have as a background:
body style="background-color:Powderblue"
I know this is not a gradient.
This cannot be done in html but it can in css (specifically css3).
You would have to add a class to the body of your page or a div within it that surrounds all of your content. You can use a css gradient generator to get the code to put in your css class.
Here is a simple example on a div: http://jsfiddle.net/8fDte/
You can do the following as well if you want it on the body. Note you have to link to the css file that will store you styles.
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<LINK href="PathToCss.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY class="MyGradientClass">
</BODY>
</HTML>
CSS
This code can be generated by a css gradient generator like the one linked above.
.MyGradientClass
{
height:200px;
background-image: linear-gradient(bottom, rgb(113,61,62) 25%, rgb(147,92,93) 63%, rgb(177,120,121) 82%);
background-image: -o-linear-gradient(bottom, rgb(113,61,62) 25%, rgb(147,92,93) 63%, rgb(177,120,121) 82%);
background-image: -moz-linear-gradient(bottom, rgb(113,61,62) 25%, rgb(147,92,93) 63%, rgb(177,120,121) 82%);
background-image: -webkit-linear-gradient(bottom, rgb(113,61,62) 25%, rgb(147,92,93) 63%, rgb(177,120,121) 82%);
background-image: -ms-linear-gradient(bottom, rgb(113,61,62) 25%, rgb(147,92,93) 63%, rgb(177,120,121) 82%);
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.25, rgb(113,61,62)),
color-stop(0.63, rgb(147,92,93)),
color-stop(0.82, rgb(177,120,121))
);
}
Edit:
As Rory mentioned, CSS3 is not fully supported by all modern browsers. However, there are some tools such as PIE CSS to help IE to accept some CSS3 functionality.
It's not possible to make a gradient with HTML alone. There are new features in CSS3 which allow you to create a gradient, however these are not fully supported by all browsers.
If you'd like to read some more about CSS3 gradients, read this article
There is also a handy online tool which will create the CSS code to create a gradient of your specification, here.
Styling in external sheets is a much easier, faster and more efficient way to style your web pages especially if you have several pages that link to your style sheet(s). This allows you to change the entire styling of all of your pages at the same time with one line of code. It is ok however if you have a single page that you have up or if you need a simple page to look different by itself, inline styling is sufficient but not common. See below for quick example.
(inline styling for each page)
<!doctype html>
<html>
<head>
<title>THIS WOULD GET AGGRAVATING IF DONE ON 10 PAGES!</title>
<style="text/css">
body {background: blue; font-family: Arial, Georgian, Sans-serif; font-size: 19px;}
h1 {text-align: center, font-weight: bolder;}
p {text-indent: 20px; line-height: 25px;}
</style>
</head>
<body>
</body>
</html>
....or it would b like this
<!doctype html>
<!doctype html>
<html>
<head>
<title>THIS CHANGES SAME PARAMETERS ON 100 PAGES WITH SAME LINK INSTANTLY!</title>
<link rel="stylesheet" href="/cssfolder/yourcssheet.css" />
</head>
<body>
</body>
and your "yourcssheet.css" style sheet would look like this
/*BEGINNING OF STYLESHEET, NO OTHER CODING NECESSARY BUT SOME MIGHT PUT #meta charset utf-8 AT THE TOP BUT IS NOT NEEDED TO FUNCTION*/
body {background: blue; font-family: Arial, Georgian, Sans-serif; font-size: 19px;}
h1 {text-align: center, font-weight: bolder;}
p {text-indent: 20px; line-height: 25px;}
/*END OF STYLESHEET*/
Now instead of going through every style on each individual page head, you can simply change it all with a simple external sheet all linked together by the following.
Hope this helps. jhawk2k14#gmail.com
Use this http://www.colorzilla.com/gradient-editor/
CSS should be applied in a separate stylesheet... never apply styling inline.
There are many online tools that create Gradients. Either you can use them or you can create your own
Simply check here: http://www.cssmatic.com/gradient-generator
Also you can create your own by this way
CSS
background-image: -webkit-linear-gradient(bottom, rgb(color_code) 25%, rgb(color_code) precent%, rgb(color_code) percent%);
background-image: -moz-linear-gradient(bottom, rgb(color_code) 25%, rgb(color_code) precent%, rgb(color_code) percent%);
background-image: -ms-linear-gradient(bottom, rgb(color_code) 25%, rgb(color_code) precent%, rgb(color_code) percent%);
background-image: -o-linear-gradient(bottom, rgb(color_code) 25%, rgb(color_code) precent%, rgb(color_code) percent%);
background-image: linear-gradient(bottom, rgb(color_code) 25%, rgb(color_code) precent%, rgb(color_code) percent%);
Related
I have problem linking a CSS file from another folder (project structure & link tag in the picture below). I have read many SO questions about this but nothing can make my linking work. Am I blind or is there something I missed?
Edit: Add files content:
index.html
...
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" href="src/assets/css/style.css" />
<!-- this works fine
<style>
body {
background: rgb(100,0,255);
background: linear-gradient(0deg, rgba(100,0,255,1) 0%, rgba(100,0,255,1) 30%, rgba(255,255,255,1) 100%);
background-attachment: fixed
}
</style>-->
</head>
...
style.css
body {
background: rgb(100,0,255);
background: linear-gradient(0deg, rgba(100,0,255,1) 0%, rgba(100,0,255,1) 30%, rgba(255,255,255,1) 100%);
background-attachment: fixed
}
Because your project is actually a React project, so you have to import CSS file in App.js.
For example, assuming that your global.css is located in /styles directory,
you have to import it in App.js.
./styles/global.css
body {
background: rgb(100,0,255);
background: linear-gradient(0deg, rgba(100,0,255,1) 0%, rgba(100,0,255,1) 30%, rgba(255,255,255,1) 100%);
background-attachment: fixed
}
./App.js
import './styles/globals.css';
function App(props) {
}
Ok so apparently it is because my project is actually a React project so the CSS had to be imported in App.js
I want this background on my project like this:
This is easily achieved using CSS linear-gradient()s:
body {
--gridColor: #eee;
--gridSize: 10px;
background-image:
linear-gradient(to right, var(--gridColor) 10%, transparent 10%),
linear-gradient(to bottom, var(--gridColor) 10%, transparent 10%);
background-size: var(--gridSize) var(--gridSize);
}
See also Lea Verou's CSS patterns for more elaborate designs.
So i dont have set margines on section before footer but somehow it is separated and i cant seem to find out why. Any idea? thanks!
html:
<section>
<div class="content"></div>
</section>
<footer>
<div id="footer"></div>
</footer>
and css:
.content{
background-image: linear-gradient(bottom, rgb(135,127,127) 0%, rgb(37,37,35) 69%);
background-image: -o-linear-gradient(bottom, rgb(135,127,127) 0%, rgb(37,37,35) 69%);
background-image: -moz-linear-gradient(bottom, rgb(135,127,127) 0%, rgb(37,37,35) 69%);
background-image: -webkit-linear-gradient(bottom, rgb(135,127,127) 0%, rgb(37,37,35) 69%);
background-image: -ms-linear-gradient(bottom, rgb(135,127,127) 0%, rgb(37,37,35) 69%);
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0, rgb(135,127,127)),
color-stop(0.69, rgb(37,37,35))
);
#footer{
background:url(images/footer.png) left top no-repeat;
height:450px;
}
Try applying a CSS Reset before you do any of your styling: http://meyerweb.com/eric/tools/css/reset/
In HTML4 specs (http://www.w3.org/TR/CSS21/sample.html) there is a default stylesheet defining margins and other formatting. It can cause that the browser renders margin even though you didn't write it in your CSS.
As far as I know, there is no specs for a default stylesheet in HTML5 yet, thus the browsers use their own default stylesheets.
Therefore, it seems that the margin used by section element has some margin set by default (in the browser). The best way how to avoid this is to reset CSS.
http://html5doctor.com/html-5-reset-stylesheet/ is probably a good solution for you.
i have html code
<pre>
line 1
line 2
line 3
</pre>
how can i put some css style to the "lines" inside <pre>, without adding other wrapper into it?
what i mean is something like
pre lines{ color: red}
i'm having difficulties on finding the css selector for that. Thanks in advance.
You can use this little CSS3 trick, with gradients. This will create automatically, without extra spans, a "zebra" effect:
background: #555;
background-image: -webkit-linear-gradient(#555 50%, #505050 50%);
background-image: -moz-linear-gradient(#555 50%, #505050 50%);
background-image: -ms-linear-gradient(#555 50%, #505050 50%);
background-image: -o-linear-gradient(#555 50%, #505050 50%);
background-image: linear-gradient(#555 50%, #505050 50%);
background-position: 0 0;
background-repeat: repeat;
background-size: 4.5em 4.5em;
Try different CSS "line-height" so that the text appears correctly.
see: http://www.dte.web.id/2012/03/css-only-zebra-striped-pre-tag.html#.UUoV6lugkoM
If you want add color to all lines in pre, just add
pre {color: red;}
But if you want to add color to some lines, you need extra markup:
<pre>
<span>Line1</span>
line2
<span>Line3</span>
</pre>
pre span {color: red;}
Greetings all,
I'm using a gradient background with -webkit-gradient. It's not working on Chrome 8.0.552.224 on Windows 7, but I could swear it was recently working on Chrome-OS X. It's Monday so perhaps I'm missing something obvious, but if so I can't figure it out. I'd appreciate your taking a look. The sample code here will work on Firefox but doesn't display a gradient in Chrome:
Thanks,
-Northk
<!DOCTYPE html>
<html lang="en">
<head>
<title>Gradient test </title>
<style>
.main-header
{
padding-top: 50px;
min-height: 50px;
background: -webkit-gradient(linear, 0%, 0%, 0%, 100%, from(#fff), to(#000));
background: -moz-linear-gradient(top, #fff, #000);
border: 1px solid #000;
}
</style>
</head>
<body>
<div class="main-header">
THIS WORKS ON FIREFOX BUT DOESN'T WORK ON CHROME-WINDOWS 7!
</div>
</body>
</html>
Seems I just got the syntax wrong. Here's how it should be:
background: -webkit-gradient(linear, center top, center bottom, from(#fff), to(#000));
Be aware in Chrome 16.0.912.75m still has a small CSS bug/issue when parsing style:
background:-webkit-linear-gradient (top,gray 0,#A0A0A0 100%);
This will not work, because of spaces between -webkit-linear-gradient and start bracket.
Deleting additional spaces will solve the issue as well as minifying CSSs.
Try this
background: -webkit-linear-gradient(#DDDDDD, #ffffff);