首页 > 解决方案 > 不明白为什么我的 CSS 不起作用?

问题描述

我认为我的链接路径还可以。但是css无法显示。这是我的数据结构。![在此处输入图像描述][1]

这是我的代码。我在 admin_menu.jsp 中编码![在此处输入图像描述][2]

这是错误,它显示:“加载资源失败:服务器响应状态为 404 ()”![在此处输入图像描述][3]

好的,我试试代码:

<link rel="stylesheet"  href="./css/common.css" type="text/css"/>
<link rel="stylesheet"  href="./css/main.css" type="text/css"/>

它还不行。所以我放弃了链接,我只是编码:

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<head>
<style type="text/css">
.sidebar-wrap{float: left;width: 189px;min-height:700px;background: 
#f2f2f2;border-right:1px solid #ccc;/*cursor:e-resize;*/}
.main-wrap{margin-left: 190px;min-height:100%;}
.sidebar-title{height: 40px;line-height: 40px;text-indent:1em;font-size: 
24px;text-align: left;}
.sidebar-title h1{font-weight: normal;}
.sidebar-content{padding-top: 5px;}
.sidebar-list li{border:1px solid #e5e5e5;border-width:1px 0;}
.sidebar-list li .icon-font{margin-right: 5px;color: #888;font-size: 
14px;}
.sidebar-list li a{padding: 0 16px 0 20px;display: block;height: 
38px;line-height: 38px;color: #333;}
.sidebar-list li a:hover{background: #fff;color: #1963AA;}
.sub-menu{border-top: 1px solid #e5e5e5;background: #fff;}
.sub-menu li{padding-left: 21px;}
.sub-menu li.on{background: #1963AA;}
.sub-menu li.on a{background: #1963AA;color: #fff;}
.sub-menu li.on .icon-font{color: #fff;}
.sub-menu .icon-font{font-size: 11px;}
/* main */
.crumb-wrap{height: 40px;line-height: 39px;border-bottom: 1px solid 
#e5e5e5;background: #f5f5f5;}
.crumb-list{padding-left: 12px;}
.crumb-list .icon-font{margin-right: 5px;}
.crumb-step{margin: 0 5px;color: #b2c2e0;font-family: serif;}
.search-wrap{padding: 15px 0;border-bottom: 1px solid #e5e5e5;}
.search-tab tr{line-height: 35px;}
.search-tab th{text-align: right;padding-right:10px;font-weight: 
normal;}
.search-tab td{padding: 0 5px;}
.common-text{height: 23px;line-height: 23px;padding: 2px 4px;border: 
1px 
solid #ccc;background: #fff;border-radius:5px;}
.result-wrap{padding:10px 20px;border-bottom: 1px solid #e5e5e5;}
.result-title{line-height: 35px;padding-bottom: 5px;overflow: 
hidden;}
.comment-title{line-height: 35px;margin-bottom: 10px;overflow: 
hidden;}
.result-list a{margin-right: 15px;}
.result-list i{padding-right: 5px;}
.result-tab{border-collapse:collapse;border: 1px solid #ddd;}
.result-tab th{font-weight: normal;font-size: 15px;text-align: 
left;background: url(../images/tab-thbg.png) #f9f9f9 0 bottom repeat- 
x;}
.result-tab th,.result-tab td{padding:5px;border-bottom: 1px solid 
#ddd;border-right: 1px solid #e1e1e1;}
.result-tab tr{line-height:35px;}
.result-tab th.tc,.result-tab td.tc{text-align: center;}
.result-tab tr:nth-child(odd){background: #f9f9f9;}
.result-tab tr:hover{background: #f1f1f1;}
.result-tab tr.even-tr{background: #e9fff2;}
.comment-tab{border-bottom: 1px solid #ddd;padding-left: 15px;margin- 
bottom: 10px;}
.comment-tab a{float: left;}
.comment-tab a.on{padding: 0 15px;background: #49afcd;color: 
#fff;border-radius:5px 5px 0 0;}
/* config */
.config-items{margin-bottom: 25px;}
.config-title{margin-bottom: 10px;}
.config-title h1{font-size: 14px;font-weight: normal;}
.config-title h1 i{margin-right: 5px;font-size: 12px;}
.columns-title{padding: 10px 0;height: 35px;line-height: 
35px;overflow: hidden;}
/*.columns-title .comment-tab{padding-left: 0;}*/
.visitor-img{float: left;}
.visitor-info{float: left;padding-left: 10px;line-height:23px;}
.visitor-email{color: #aaa;}
.short-wrap a{margin-right: 20px;}
.short-wrap a i{margin-right: 5px;}
.res-lab{display: inline-block;width: 150px;padding-right: 10px;text- 
align: right;}
.sys-info-list li{line-height: 35px;border-bottom: 1px dashed 
#eaeaea;}
.res-lab{color: #909090;}
.res-info{font-size: 15px;}
.sort-input{width: 25px;text-align: center;}
</style>
</head>
<body>
<div class="topbar-wrap white">
    <div class="topbar-inner clearfix">
        <div class="topbar-logo-wrap clearfix">
            <h1 class="topbar-logo none"><a href="index.html" 
class="navbar-brand">后台管理</a></h1>
            <ul class="navbar-list clearfix">
                <li><a class="on" href="index.html">首页</a></li>
                <li><a href="#" target="_blank">网站首页</a></li>
            </ul>
        </div>
        <div class="top-info-wrap">
            <ul class="top-info-list clearfix">
                <li><a href="#">管理员&lt;/a></li>
                <li><a href="#">修改密码</a></li>
                <li><a href="#">退出&lt;/a></li>
            </ul>
        </div>
    </div>
</div>

它有效。但我不喜欢它。[1] : https ://i.stack.imgur.com/c5ax4.png [ 2 ]: https ://i.stack.imgur.com/hKFHb.png [3]:https://i.stack。 imgur.com/s38eb.png

标签: javacsspath

解决方案


您在 href 中为 css 使用的路径是:

/Shop/manage/css/common.css
/Shop/manange/css/main.css

问题是您的路径以字符/开头。它对应于您当前操作系统的根目录。

从您提供的图像中,您应该尝试:

./css/common.css
./css/main.css

./应该对应于admin_menu.jsp 文件的当前文件夹。

https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/Dealing_with_files

https://en.wikipedia.org/wiki/Path_(计算)


推荐阅读