You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法关联外部CSS样式表问题求助

Troubleshooting Unlinked CSS and HTML

Hey there! Let's dig into why your external CSS isn't applying to your HTML—total bummer when styles don't show up even after checking the basics. First off, your code structure looks totally correct on the surface, so let's go through the most common fixes step by step:

Common Fixes to Try

  • Double-check the file path & naming
    Make sure your main.css file is in the exact same folder as your HTML file. If it's in a subfolder (like a css directory), your link tag should look like <link rel="stylesheet" type="text/css" href="css/main.css">. Also, watch out for typos or capitalization differences—on macOS/Linux, Main.css is not the same as main.css, which can cause a 404 error.

  • Use browser dev tools to diagnose
    Hit F12 to open Developer Tools, then go to the Network tab. Refresh your page and look for main.css in the list of requests:

    • If you see a 404 status: Your path is wrong—fix the href value to point to the correct location of your CSS file.
    • If it loads with a 200 status: Click on it and check the Response tab to make sure your CSS code is showing up correctly. Sometimes even after clearing cache, a hard refresh (Ctrl+F5 on Windows, Cmd+Shift+R on Mac) can force the browser to load the latest version.
  • Verify your CSS syntax
    Your CSS code looks clean, but double-check for accidental typos (like missing curly braces or semicolons). Even a tiny mistake can break the whole stylesheet.

Your Code for Reference

HTML File

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"/> 
    <title>External Style sheet </title> 
    <link rel="stylesheet" type="text/css" href="main.css"/> 
</head> 
<body> 
    <h1>Intro to CSS</h1> 
    <p> I'm blue</p> 
    <p>I can be any colour you want me to</p> 
    <p>I know you only wanna use me as a <br>example</br></p> 
</body> 
</html>

CSS File (main.css)

p{ 
    color:red; 
} 
h1{ 
    background-color:yellow; 
}

内容的提问来源于stack exchange,提问作者Amendo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 09:05:21