[英]Why won't my css stylesheet work in Sinatra?
I'm relatively new to this but as far as I can tell from my research, this should be working.我对此相对较新,但据我的研究表明,这应该可行。 I'm trying to link a css stylesheet to an.erb file.
我正在尝试将 css 样式表链接到 .erb 文件。 Here is the code I'm using:
这是我正在使用的代码:
<link rel="stylesheet" type="text/css" href="../css/stylesheet.css">
I've also tried我也试过
href="./css/stylesheet.css"
and和
href="css/stylesheet.css"
for reference my erb file and css file both sit in different subdirectorys of the same main directory.作为参考,我的 erb 文件和 css 文件都位于同一主目录的不同子目录中。 Here is the code contained within my stylesheet, just in case this is the problem:
这是我的样式表中包含的代码,以防万一这是问题:
body {
border-style: solid;
border-color: black;
border-width: 5px;
text-align: center;
background-color:powderblue;
}
h1 {
font-family: verdana;
}
h2 {
font-family: sans-serif;
}
With a server.rb
like使用
server.rb
类的
require 'sinatra'
set :public_folder, __dir__ + '/static'
get '/' do
erb :index
end
A views/index.erb
like一个
views/index.erb
类的
<link rel="stylesheet" type="text/css" href="/css/stylesheet.css">
Hi!
And your stylesheet in static/css/stylesheet.css
it should work, the important bit you may be missing is setting the public folder.您在
static/css/stylesheet.css
中的样式表应该可以工作,您可能缺少的重要一点是设置公用文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.