www.webdeveloper.com
Results 1 to 5 of 5

Thread: Descent problem

  1. #1
    Join Date
    May 2011
    Posts
    11

    Descent problem

    Hello, I wrote a simple html and css files and according to css rules the first and the third paragraph should be red because they are direct descendents of <body> but don't work and I see all three black could you help me, please?
    thanks!

    HTML Code:
    <html>
    <head> 
    <title> CSS</title> 
    </head> 
    <link rel="stylesheet" type="text/css" href="test.css" /> 
    <body>
    <p>Red text</p> 
    <div>
    <p>black text</p>
    </div>
    <p>Red text</p>
    </body>
    </html>
    Code:
     body > p {color: red;}

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    I must always start your document with a Doctype. Without a Doctype, browsers (mainly IE) enter in "quirks mode", which will spoil the CSS/JavaScript/ and even HTML/XHTML standard behavior.

    So:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    //...
    //...
    </html>
    About Doctypes:
    http://www.w3.org/QA/2002/04/valid-dtd-list.html
    Last edited by Kor; 05-12-2011 at 10:27 AM.

  3. #3
    Join Date
    May 2011
    Posts
    11
    I've writed the doctype but all three paragraph are yet black

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by paperino00 View Post
    I've writed the doctype but all three paragraph are yet black
    Impossible. This document:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    
    <style type="text/css">
    body > p {color: red;}
    </style>
    </head>
    <body>
    <p>Red text</p> 
    <div>
    <p>black text</p>
    </div>
    <p>Red text</p>
    </body>
    </html>
    Does exactly what you want. Tested in IE7, IE8, IE9, FF4, Chrome 11, Opera 11, Maxthor 2 / Win7 . Of course, it won't work in IE 6, but that is understandable. IE6 is a medieval browser, which is on his way to be extinct soon.
    Last edited by Kor; 05-12-2011 at 10:58 AM.

  5. #5
    Join Date
    May 2011
    Posts
    11
    Ok now it works
    thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles