Solved

css background image not displaying

Posted on 2014-03-12
3
405 Views
Last Modified: 2014-03-13
Trying to set background image of page with following but it will not display. Please help. Thanks.

<!DOCTYPE HTML>
<HTML>
      <head>
            <title>test</title>
            <link rel="stylesheet" type="text/css" href="styles/styles.css" />
      </head>
      
      <body>

      </body>
      
</HTML>

html {
      height: 100%;

        background: url(imgs/1.jpg) no-repeat center center fixed;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;

}

body {
      margin-top: 0;
      height: 100%;
}
0
Comment
Question by:centem
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
Comment Utility
Nothing wrong with the code
http://jsfiddle.net/GaryC123/JgeLg/

Are you sure you have the path to the image correct? Does the image really exist?
0
 

Author Comment

by:centem
Comment Utility
I moved it to the same directory that the css stylesheet is in and it works. How can I reference correctly. I have a folder called imgs and a folder called styles. I thought I could just reference the image with /imgs/1.jpg but it doesn't work.
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
In CSS files always use absolute paths from your root so

background: url(/imgs/1.jpg) no-repeat center center fixed;

will look for 1.jpg in the imgs folder which is in your root folder

Paths in CSS files are relative to the page including the CSS file unless you specify an absolute url which means preceding the path with / e.g. /imgs/1.jpg
Assuming a structure like

/root folder
     mypage.php
          /imgs
               1.jpg
          /css
               mycss.css
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now