简体   繁体   中英

Trying to connect my css with my html doc, html loads but css does not carry over. Here's my code, what am I doing wrong? [Full details in text]

Brand new to stackoverflow. Been learning code on my own and have been working on webdev over the past few months. I'm trying to connect my css file to my html doc. I am using the link tag in my html file to connect to the css file and upon viewing the html doc, the css is not carrying over.

What am I doing wrong?

Here is my html code (list.html):

<!DOCTYPE html>
<html>
<head>
  <title>My website</title>
  <link rel="stylesheet" type="text/css" href="css/list.css"/>
</head>
<body>
  <div id='container'>
    <div id='header'>
      <h1>My Website</h1>
    </div>
    <div id='content'>
      <div id='nav'>
        <h2>Navigation</h2>
        <ul>
          <li class=''>Home</li>
          <li>About</li>
          <li>Contact</li>
        </ul>
      </div>
      <div id='main'>
        <h2>Home page</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
      </div>
    </div>
    <div id='footer'>         
    </div>
  </div>
</body>
</html>

and my css code (list.css):

#header {
    background-color: #008000;
    background: #FFFFFF;
    padding: 10 px;
}

I have a folder called css on my desktop. The files in that folder are called list.html and list.css . Upon clicking on list.html, only the html shows up but not with the css applied. Shouldn't have the header in html been modified with the code I wrote for the css file? Is something about my link rel="stylesheet" type="text/css" href="css/list.css line not correct or what? what am I doing wrong?

Thanks for any help I can get!!

It seems your link tag is wrong.

check this

  1. You should check you have your file in the same folder. then your link tag should be like this -> <link rel="stylesheet" type="text/css" href="list.css"/>
  2. You should check your file name is correct.
  3. You should check your file is deleted or moved.
  4. You should check you might want to adjust it to Absolute path ->
<link rel="stylesheet" type="text/css" href="C:\Users\[Your user name]\Desktop\css\list.css">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM