Html <link rel="stylesheet" href="../css/style.css"> 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15356695/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
<link rel="stylesheet" href="../css/style.css"> is not working
提问by sanit
I have css files under css folder and jsp files under jsp folder and both folders are inside WEB-INF folder. So how can i get the css file inside jsp?
我在 css 文件夹下有 css 文件,在 jsp 文件夹下有 jsp 文件,两个文件夹都在 WEB-INF 文件夹内。那么如何在jsp中获取css文件呢?
<link rel="stylesheet" href="../css/style.css>
I have given path like this.
我已经给出了这样的路径。
回答by Simon Dorociak
Try to use this:
尝试使用这个:
<link rel="stylesheet" type="text/css" href="css/style.css" >
instead of
代替
href="../css/style.css
Here you are missing right apostrophe. Also check BalusC answerwould solve your problem.
在这里,您缺少右撇号。还要检查BalusC 答案会解决您的问题。
Note:
笔记:
Also i recommend to you create resourcesfolder on the same level as WEB-INFthen in resources folder create cssfolder and then reference css file as:
此外,我建议您创建与WEB-INF相同级别的资源文件夹,然后在资源文件夹中创建css文件夹,然后将 css 文件引用为:
WEB-INF
resources
--css
--styles.css
--js
--scripts.js
and here how to connect css with page:
以及如何将 css 与页面连接:
<link rel="stylesheet" type="text/css" href="resources/css/styles.css" />
I'm using this approach is my web project and everything works correctly.
我正在使用这种方法是我的网络项目,一切正常。
回答by Kesar Sisodiya
The @importrule is another way of loading a CSS file:
该@import规则是加载CSS文件的另一种方式:
<style>
@import url('/css/styles.css');
</style>
you can import all the styles at the same time using this trick, like:-
您可以使用此技巧同时导入所有样式,例如:-
@import url('/css/header.css') screen;
@import url('/css/content.css') screen;
@import url('/css/sidebar.css') screen;
@import url('/css/print.css') print;
回答by Kesar Sisodiya
Under a previous version of HTML, to reference an external css file in a another folder, the href attribute required the actual file path such as href="./CSS/filename.css" Using HTML5, I have my css files in a sub-folder and to my amazement, the above approach doesn't work which I could not understand. I remove the dot at the beginning, that didn't work. Then I remove the stating slash(/), again it didn't work. It seems HTML5 only requires the actual css file name to work. So even with the css file in a sub-folder href="filename.css" works!
在以前版本的 HTML 下,要引用另一个文件夹中的外部 css 文件,href 属性需要实际文件路径,例如 href="./CSS/filename.css" 使用 HTML5,我将 css 文件放在子目录中-文件夹,令我惊讶的是,上述方法不起作用,我无法理解。我在开始时删除了点,这不起作用。然后我删除了斜杠(/),它再次不起作用。似乎 HTML5 只需要实际的 css 文件名即可工作。因此,即使使用子文件夹中的 css 文件 href="filename.css" 也能工作!
回答by sanit
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Form</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
</html>