1

I have an external CSS file name main.css. The ID of nav and footer are working fine but the ID of header doesn't work. When I put the header part in HTML file, it works.
Why does it not work in CSS file.

HTML File:

        <!DOCTYPE html>
        <html>
        <head>
            <link rel="stylesheet" href="main.css">
            <meta charset="UTF-8">
        </head>    
        <body>    
            <div id="header">
                <h1>Furkan İlhan</h1>
            </div>
            
            <div id="nav">
                Hakkında<br>
                Kariyer<br>
            </div>
        
            <div id="footer">
            Tüm Hakkı Saklıdır. Furkanilhan.com
            </div>
        </body>    
        </html>

CSS File:

    <style>        
        #header {
            background-color:black;
            color:white;
            text-align:center;
            padding:5px;            
        }
        
        #nav {
            line-height:30px;
            background-color:#eeeeee;
            height:300px;
            width:100px;
            float:left;
            padding:5px;    
        }
        
        #footer {
            background-color:black;
            color:white;
            clear:both;
            text-align:center;
            padding:5px;
        }
    </style>

The image of result

6
  • 1
    you have defined header as class and referring it in css using #header..use .header and it will work Commented May 27, 2016 at 8:07
  • Is the css in the same file Commented May 27, 2016 at 8:13
  • it is working for me in my text editor , you need to check on your end Commented May 27, 2016 at 8:15
  • yes it is in the same file. all others are work fine but only #header is not work. you can see in the image below @PranavKumar Commented May 27, 2016 at 8:16
  • is the issue resolved @Furkanİlhan Commented May 27, 2016 at 8:21

3 Answers 3

3

Because You Use class="header" Property And External CSS Defined ID # Header.

So You Change

#header {

}

Use This Code In CSS

.header {

}

Work 100% Perfectly

Sign up to request clarification or add additional context in comments.

Comments

2
  1. Dhaval is wrong - You had it right with the #header since you have it as an id in your HTML.

  2. remove the <style></style> tags from your CSS sheet.

Let me know how you go

Regards,
Kostantinos

1 Comment

No problem, glad to have helped :)
0

It seems the links require id to be defined in each <div></div> to work, not just the class name.

My case was a bit different, where the links didn't work with just class defined in html and .clasname defined in css file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.