1.my-div{
2 background-color: #00f; /* Blue */
3}
4.div-image{
5 background-image: url("Image Path");
6 background-position:
7 top right | left center | bottom center
8 top left | right center | bottom right
9 top center | center center | bottom left ;
10 /* Use any option that met your requirements*/
11 background-size: cover; /* Set the image to cover all the div */
12 background-repeat: no-repeat; /* Commonly used for that situation */
13 background-attachment: fixed; /* the image will stay with you while scrolling same as position: fixed*/
14 /* Use background-attachment: scroll [Default Value]; to remove fixed effect */
15}
16/*
17 Background shortHand
18 background: background-color background-image background-repeat background-position
19*/
1/* Color (Example: red): */
2html,body {
3 background-color: red;
4}
5
6/* Image (Example: your.picture): */
7html,body {
8 background-image: url("your.picture");
9}
1/* Answer to: "adding background image css" */
2
3/*
4 The background-image property sets one or more background images
5 for an element.
6
7 By default, a background-image is placed at the top-left corner
8 of an element, and repeated both vertically and horizontally.
9
10 Tip: The background of an element is the total size of the
11 element, including padding and border (but not the margin).
12
13 Tip: Always set a background-color to be used if the image is
14 unavailable.
15*/
16
17/* Set a background-image for the <body> element: */
18
19body {
20 background-image: url("paper.gif");
21 background-color: #cccccc;
22}
23
24/* Set two background images for the <body> element: */
25
26body {
27 background-image: url("img_tree.gif"), url("paper.gif");
28 background-color: #cccccc;
29}
1/* There are several ways of setting a background, like in HTML or CSS
2 (I advise you to set it in CSS) You can set a colour or image with
3 the same attribute: */
4
5/* Setting the colour in a div, body, html (html is the whole page),
6 class, and id: */
7div, body, html, .myClass, #myId {
8 background-color: grey;
9}
10/* Setting the image: */
11div {
12 background: url("img.jpg");
13}
14/* If you want to call an image from a specific directory use a '/'.
15 For example, the image is in a folder called 'Images' (the HTML
16 and CSS files have to be in the same folder as the 'Images folder') */
17div {
18 background: url("Images/img.jpg");
19}