Log in

View Full Version : Why isn't this working



Kage Kazumi
10-22-2012, 10:43 PM
div#somediv h1{
background-color:#000;
}

Now the above is just an example, but I saw someone typing CSS that way (and have seen it many times), but I can never get it to work. I always have to use something like:


h1{
background-color:#000;
}

Does it have something to do with my DOC type for the html you think?



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


CSS header file would say:



@charset "utf-8";
/* CSS Document */

traq
10-22-2012, 11:02 PM
is your <h1> inside a <div> with id="somediv"?


<style> div#somediv h1{ background-color: red; }</style>
<h1>Not in #somediv</h1>
<div id="somediv">
<h1>In #somediv</h1>
</div>

Kage Kazumi
10-22-2012, 11:07 PM
is your <h1> inside a <div> with id="somediv"?


<style> div#somediv h1{ background-color: red; }</style>
<h1>Not in #somediv</h1>
<div id="somediv">
<h1>In #somediv</h1>
</div>

Yes it is. However, Google Chrome, Fire Fox, and Safari ignore the css when I type it that way (yes lastest version of browsers installed).

traq
10-22-2012, 11:12 PM
what OS? seems to work for me (http://jsfiddle.net/QUCAy/) (Google/Firefox/Safari on Win; Google/Firefox/Opera on linux).

Kage Kazumi
10-22-2012, 11:15 PM
what OS? seems to work for me (http://jsfiddle.net/QUCAy/).

Well I just tried it in Mac Dreamweaver and preview in browser and it works fine. Windows 7 not so much.