Question:

Why isn't my CSS working with Firefox?

by  |  earlier

0 LIKES UnLike

I have an external style sheet containing this code:

<style type="text/css">

<!--

body

{

background-image: url('TKFbg2.jpg');

background-repeat: no-repeat;

background-attachment: scroll;

background-color: #003300;

margin-top: 0in;

margin-left:

}

table

{

padding-bottom: 0;

}

div.links

{

background-image: url('links.jpg');

background-repeat: no-repeat;

font-family: Blackadder ITC, @Batang, Fantasy;

font-size: 18pt;

color: #FFFFFF;

width: 140px;

margin-top: 0.5in;

padding-top: 0.1in;

padding-bottom: 0.1in;

text-align: center;

}

div.linksmall

{

font-size: 16pt;

}

a:link

{ color: #FFFFFF;

text-decoration: none;

font-family: Blackadder ITC, @Batang, Fantasy;

}

a:hover

{ color: #C0C0C0;

font-weight: bold;

text-decoration: none;

font-family: Blackadder ITC, @Batang, Fantasy;

}

a:visited

{ color: #C0C0C0;

text-decoration: none;

font-family: Blackadder ITC, @Batang, Fantasy;

}

div.home

{

margin-top: 0.5in;

padding-top: 0.1in;

padding-bottom: 0.1in;

padding-left: 0.5in;

width: 640px;

color: #FFFFFF;

}

div.content

{

background-image: url('knotbg.jpg');

background-repeat: no-repeat;

margin-top: 0.5in;

margin-left: 0.4in;

padding-top: 0.1in;

padding-bottom: 0.1in;

padding-left: 0.6in;

padding-right: 0.6in;

width: 640px;

color: #FFFFFF;

}

h3

{

font-family: Blackadder ITC, @Batang, Fantasy;

color: #FFFFFF;

font-size: 30pt;

}

-->

</style>

I am linking it within the head of the html doc like this:

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

Only bits of it actually work with Firefox (everything works with IE). The background images will only show up if the background css is put dirrectly into the head of the html doc. The links show up in bold, but not in the correct font, and the padding and margins work in some places but not others. I'm using <div class="etc"> to denote the various blocks, divisions, w/e. What part of this is not compatible with Firefox?? Many thanks in advance!!

 Tags:

   Report

3 ANSWERS


  1. It&#039;s not that your CSS is incompatible with Firefox -

    it&#039;s that is wrong. Firefox recognizes the errors and

    does what it&#039;s supposed to do, i.e., ignores the bad

    declarations.

    /* lose the &lt;style&gt; tags and the HTML type comments -

    they&#039;re invalid in external style-sheets */

    body {

    background-image: url(&#039;TKFbg2.jpg&#039;);

    background-repeat: no-repeat;

    background-attachment: scroll;

    background-color: #003300;

    /* don&#039;t declare units, if length is 0 */

    margin-top: 0;

    /* declare a measurement or delete it */

    margin-left: 0;

    }

    table {

    padding-bottom: 0;

    }

    /* div.links declares a class of divs, implying

    there could be more than one such div - if there&#039;s

    only one, us id instead as div#links and change

    your HTML to &lt;div id=&quot;links&quot;&gt;

    either approach will work, but the id approach is

    better, if there&#039;s only one such div, since it

    better reflects you intent */

    div.links {

    background-image: url(&#039;links.jpg&#039;);

    background-repeat: no-repeat;

    /* enquote font-family names that contain spaces -

    there should be a default font (last one in your list

    that is guaranteed to be on every user&#039;s box, or you&#039;ll

    get the browser&#039;s default, if none of your declared

    fonts is available - lose the @ sign */

    font-family: &quot;Blackadder ITC&quot;, Batang, Fantasy;

    font-size: 18pt;

    color: #FFFFFF;

    width: 140px;

    margin-top: 0.5in;

    padding-top: 0.1in;

    padding-bottom: 0.1in;

    text-align: center;

    }

    div.linksmall {

    font-size: 16pt;

    }

    /* put base attributes on a element - let :hover,

    etc. pseudoclasses inherit...fewer declarations */

    a {

    text-decoration: none;

    /* enquote font-family names that contain spaces -

    lose the @ sign */

    font-family: &quot;Blackadder ITC&quot;, Batang, Fantasy;

    }

    a:link {

    color: #FFFFFF;

    }

    a:hover {

    color: #C0C0C0;

    font-weight: bold;

    }

    a:visited {

    color: #C0C0C0;

    }

    /* div.home declares a class of divs, implying

    there could be more than one such div - if there&#039;s

    only one, us id instead as div#home and change

    your HTML to &lt;div id=&quot;home&quot;&gt;

    either approach will work, but the id approach is

    better, if there&#039;s only one such div, since it

    better reflects you intent */

    div.home {

    margin-top: 0.5in;

    padding-top: 0.1in;

    padding-bottom: 0.1in;

    padding-left: 0.5in;

    width: 640px;

    color: #FFFFFF;

    }

    /* div.content declares a class of divs, implying

    there could be more than one such div - if there&#039;s

    only one, us id instead as div#content and change

    your HTML to &lt;div id=&quot;content&quot;&gt;

    either approach will work, but the id approach is

    better, if there&#039;s only one such div, since it

    better reflects you intent */

    div.content {

    background-image: url(&#039;knotbg.jpg&#039;);

    background-repeat: no-repeat;

    margin-top: 0.5in;

    margin-left: 0.4in;

    /* when declaring all four padding attributes, collapse

    to shorthand form - order is top, right, bottom, left;

    since you&#039;re repeating, it could further shortened to

    padding: 0.1in 0.6in */

    padding: 0.1in 0.6in 0.1in 0.6in;

    width: 640px;

    color: #FFFFFF;

    }

    h3 {

    /* enquote font-family names that contain spaces  -

    lose the @ sign */

    font-family: &quot;Blackadder ITC&quot;, Batang, Fantasy;

    color: #FFFFFF;

    font-size: 30pt;

    }


  2. when referring to a &quot;div&quot; in your html page, in an external/internal style sheet, you never use &quot;div.something&quot;.  Instead, you would type &quot;#something&quot;.  so to give you an example from your own CSS page:

    #content

    {

    background-image: url(&#039;knotbg.jpg&#039;);

    background-repeat: no-repeat;

    margin-top: 0.5in;

    margin-left: 0.4in;

    padding-top: 0.1in;

    padding-bottom: 0.1in;

    padding-left: 0.6in;

    padding-right: 0.6in;

    width: 640px;

    color: #FFFFFF;

    }

    The reason all your code works with internet explorer, but not firefox, is actually one of the reasons why people choose firefox over internet explorer for testing web pages.  If a web page displays correctly in IE, but not in Firefox, that means that there are errors in the code.  The reason that IE displays erroneous code correctly is because it has a built-in tool that auto-corrects some minor errors.  Always use, and never doubt Firefox.

    Oh.  And div.something works in IE because IE still accepts HTML 1.0, which is ANCIENT.  

    Hope this helped.

  3. Your problem is your comment tags.  &lt;!-- and --&gt;  You shouldn&#039;t use those in stylesheets ever! but IE lets you get away with it, Firefox doesn&#039;t.

    The correct way of putting comments in stylesheets is this:

    /* This is a comment.  */

    I&#039;m also not sure if you need to put the &lt;style&gt; tags in either or the comment tags anyway.  I think that&#039;s only necessary if you are putting the style information in your webpage, instead of a stylesheet.  I&#039;ll give you the link to stylesheets at W3C schools and you can check anything else you need to.  W3C are THE web standards people so what they say goes.  :-)

    http://w3schools.com/css/default.asp

    All the best!

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.