0

I'm trying to use loading animation using jQuery. I've tried different paths for css file like

<link href="css/animation.css" type="text/css" rel="stylesheet">

<link href="../css/animation.css" type="text/css" rel="stylesheet">

but still CSS file is not getting loaded in the html file. When I kept the CSS file in the same folder as the html file then it worked correctly.

My folder structure...

Folder structure

index.html

 <html>
 <head>
 <title>Loading Animation using jQuery</title>
 <script src="js/jquery.js"></script>
 <script src="js/jquery.backstretch.js"></script>
 <link href="css/animation.css" type="text/css" rel="stylesheet">
 </head>
 <body>
 <div id="loader">
 </div>
 <h2>Hi There</h2>
  <script>

    $(window).load(function(){
        $("#loader").delay(10000).hide(0).fadeOut("slow");
    });
  </script>
 </body>
 </html>

animation.css

   #loader{
    z-index:999999;
    display:block;
    position:fixed;
    top:0;
    left:0;
    width:100%;
    height:100%;
    background:url(images/loader.gif) 50% 50% no-repeat rgb(249,249,249); 
     }

The js files are being loaded correctly but the css file is not..Can't understand where I'm going wrong..

5
  • what is your folder structure? how are you html and css files placed? Commented Dec 9, 2015 at 7:03
  • @gurvinder372 The css file is placed inside css folder as shown in the screenshots above..Please tell me if any extra information is required. Commented Dec 9, 2015 at 7:05
  • Have you tried looking in your console? There could be errors from your JavaScript files that are preventing your CSS from loading. You should place your CSS before your script tags to prevent this from occurring. Commented Dec 9, 2015 at 7:06
  • 1
    I suggest using the developer console in your browser to find out what's wrong. Commented Dec 9, 2015 at 7:06
  • 1
    In chrome, go to developers tools by F12, go to network and filter by CSS type if necessary, if the file is displayed in red then it hasn't been loaded; so right click and open link in new tab to check the absolute path in the address bar to identify the issue. Commented Dec 9, 2015 at 7:08

7 Answers 7

2

There should not be any problem with loading your CSS file,

since the folder CSS is in the same directory level as your HTML file.

But the image thats being used in the CSS file is one level up from your CSS file.

Try changing

background:url(images/loader.gif) 50% 50% no-repeat rgb(249,249,249); 

to

background:url(../images/loader.gif) 50% 50% no-repeat rgb(249,249,249); 
Sign up to request clarification or add additional context in comments.

Comments

0

Open your project in editor, go to the folder where your css file is there. Drag and drop your css file on to the code. It will automatically generate the path for you. Hope this will help.

Comments

0

Open your developer tools, in the network tab - select the CSS option. Should should see something like the image below.

enter image description here

In your case it should be 404, you can copy the full link that is request by the browser and debugging and fixing then will be easier for you that way.

Comments

0

i saw ur folder structure as per your structure following is right link of your external css link.

and also check animation.css is available in css folder

Comments

0

if you are running this application in chrome browser. Just press clt+shift+j OR F12 to see the error.Like the attached image you can see the error on console tab, just fix that

Comments

0

You can give reference to your CSS file using below code

<link href="css/animation.css" type="text/css" rel="stylesheet">

But you have to modify your CSS file

background:url(../images/loader.gif) 50% 50% no-repeat rgb(249,249,249); 

Comments

0

You need to determine first whether the CSS file is actually not loaded by checking the network tab as Yasser stated.

  1. If the CSS is not loaded, then you need to check if the CSS file animation.css actually exist in your CSS folder.
  2. If the CSS is loaded, then, take help of developer tools to understand what CSS is being applied. If there is a trouble in that, please share the same.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.