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

CSS样式表功能异常:VS Code中HTML页面样式不生效求助

CSS样式未生效的问题排查与修复

问题根源及修复方案

  • link标签拼写错误
    • rel属性误写为sytlesheet,正确拼写应为stylesheet
    • CSS文件路径中的csss多了一个s,应改为css,路径错误会导致浏览器无法加载样式文件
  • .login元素边框样式缺失
    仅设置border-width和border-color无效,因为默认border-style为none,必须添加border-style属性(如solid)才能显示边框

修正后的HTML代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/Untitled/css/style.css">
    <title>License Manager</title>
</head>
<body>
    <div class="login">
        <textarea rows="1" cols="20">
        password
        </textarea>
        <button>
        Authenticate
        </button>
    </div> 
</body>
</html>

修正后的CSS代码

body{
    background-color: gray;
}

.login{
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
    border-width: 10px;
    border-color: black;
    border-style: solid;
    width: fit-content; /* 适配内容宽度,避免元素占满整个视口 */
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 23:48:25