1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

CSS Not Working

Discussion in 'HTML & Website Design' started by Dr. Anthony Rodriguez, Jun 13, 2020.

  1. #1
    Hi!
    I am learning HTML/CSS.
    Here's some HTML code for index.html :
    
    <!DOCTYPE html>
    <html>
    <head>
    <title>Money By Tony</title>
    <meta chartset="UTF-8">
    <link rel="stylesheet" href="style.css">
    </head>
    <body>
    <h1>Home</h1>
    <p style="color:red;">
    Hello world!
    </p>
    </body>
    </html>
    
    Code (markup):
    Here's some CSS code for style.css :
    h1 {color=red;}
    When displayed , "Home" is not "red" but "Hello world!" is "blue." What am I doing wrong?
    Thanks!
    Dr. T
     
    Last edited by a moderator: Jul 3, 2020
    Dr. Anthony Rodriguez, Jun 13, 2020 IP
  2. Saputnik

    Saputnik Active Member

    Messages:
    74
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    80
    #2
    Try this:

    h1 {color: red;}

    or

    h1 {color: #FF0000;}
     
    Saputnik, Jun 13, 2020 IP
  3. justinmidlet

    justinmidlet Member

    Messages:
    23
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #3
    change the style.css with this, and it will works.
    h1 {
    color: red;
    }
     
    justinmidlet, Jun 13, 2020 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #4
    1) Use a : not a =

    2) It's charset, not chartset. Char, short for character. "Character set"

    3) The charset META should be before all content bearing elements as it determines what text characters are valid. Failing to do so forces the browser to restart over from the beginning when it hits said META tag. TITLE is a "content bearing element".

    4) 99% of the time you see style="" you're looking at incompetence and ineptitude. Don't do that. The only time style="" should be used is for things like tag clouds, or HTML based charts and graphs, where values like font-size or width/height HELP convey meaning. Otherwise presentation does NOT belong in your markup.
     
    deathshadow, Jun 13, 2020 IP
    JEET likes this.
  5. LeylaKondakova

    LeylaKondakova Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    Try not to write properties of CSS in the body of HTML
     
    LeylaKondakova, Jul 3, 2020 IP
  6. Md Rofiqul Islam

    Md Rofiqul Islam Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #6
    use h1 {color: red;}
    not h1{color=red}
     
    Md Rofiqul Islam, Aug 12, 2020 IP
  7. brandon_wallace

    brandon_wallace Peon

    Messages:
    23
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    3
    #7
    It is highly recommended to write the CSS only in the style.css file that you have in the head section of you page, not in the HTML.
     
    brandon_wallace, Nov 15, 2020 IP
  8. hibiscustechno

    hibiscustechno Well-Known Member

    Messages:
    163
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    175
    #8
    You can write this css in style.css or inline under <style> </style> block and add the following css rule

    h1 { color:red; }

    if sill you are not getting the desired result you can mark rule as 'important' with the following rule

    h1 { color:red !important; }
     
    hibiscustechno, Dec 2, 2020 IP