?
Solved

css background image not displaying

Posted on 2014-03-12
3
Medium Priority
?
435 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 39924247
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
ID: 39924287
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
ID: 39924306
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

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Suggested Courses

762 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