CSS Not Working in Stylesheet

CSS not working in stylesheet

This is just a shot in the dark as (at the time of this post) you haven't provided source code.

Make sure you're linking to your stylesheet using a link tag in the head of the HTML document.

If you had:

<style type="text/css">
/* <![CDATA[ */
#someid
{
margin: 0;
padding: 3px 12px;
}
/* ]]> */
</style>

You'll need to have

#someid
{
margin: 0;
padding: 3px 12px;
}

in your CSS file with:

<link rel="stylesheet" type="text/css" href="path/to/style.css" />

to link to the stylesheet.

Some common newbie mistakes include:

  • <style type="text/css" src="path/to/style.css">: because it's a similar syntax to the <script> tag, which would make sense, but is invalid
  • <link rel="stylesheet" src="path/to/style.css">: but link elements use href not src
  • placing link elements within the body: although browsers will tend to manage link elements in the body, there are likely going to be some errors, and it's not a defined behavior
  • not specifying a doctype declaration: allows the browser to go into quirks mode, which is never a good idea.

CSS External Style Sheet isn't working, but the exact same CSS was woking on an internal Style Sheet

So, I've found the problem. It turned out I encoded it in UTF-8 Bom( I'm not sure that's the name of the enconding type) and that was causing problems with the browsers and the external style sheet, witch wasn't enconded in the same format. I'm going to mark this awnser had having solved my problem.

The solution is enconding the HTML source file in UTP-8, or other files that are supported and enconding the HTML and CSS source files in the same format.

Thank you for anwsering, tough.

CSS stylesheet not loading

Check the file name,sometimes when you rename via PC it tends to add layout.css.txt change the file name to just .css.

Move the file to the root where you have you HTML don't create any sub-folders for time being.

Please mention if your trying to upload to a server or just practicing,so we can give you precise instructions.

Complete list of reasons why a css file might not be working

  1. Are you sure the stylesheet is loaded? You can see it using the "Net" tab of Firebug on firefox, or on "Network" tab of the Console of your browser.

  2. (If 1 works) can you have a simple sample style and see whether this is getting applied (and visible in the console)?

Some CSS styles in css file are not applied, but they work when added to header of Html page

Seems like your CSS file is cached. In Django static files get cached by default so try opening the page in incognito mode or try doing hard refresh(shift + f5 in chrome, ctrl + f5 in firefox).

External CSS Stylesheet not loading

Try rel="stylesheet" instead of rel="css"

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

And if your file path is correct then it must load css, simple as that



Related Topics



Leave a reply



Submit