简体   繁体   中英

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. 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. 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

require 'sinatra'

set :public_folder, __dir__ + '/static'

get '/' do
  erb :index
end

A views/index.erb like

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM