編集:興味深いものを見つけました。CSS は IE8 では機能しますが、Firefox では機能しません。これは文字エンコーディングの問題だと思いますか?
私は自分の Web サーバーを作成する方法を学ぼうとしています。サーバーを起動して実行することはできましたが、何らかの理由で css が表示されません。ただし、Javascript は問題なく動作します。css ファイルは読み込まれますが、スタイルが Firebug に表示されません。ここで私が間違っていることを誰かに教えてもらえますか?
サーバーのコードを以下に示します。サーバーを実行するには、空のリストを「開始」するだけです。または、必要に応じてコードベース全体をここにプルすることもできます: https://github.com/dm9600/webserver
require 'socket'
def start(args)
webserver = create_server args
basepath = './app/'
while (session = webserver.accept)
puts "HTTP/1.1 200/OK\nContent-type:text/html\n\n"
session.print "HTTP/1.1 200/OK\nContent-type:text/html\n\n"
request = session.gets
puts "request" + request
trimmedrequest = trim_request(request)
filename = trimmedrequest.chomp
begin
displayfile = find_file(filename)
content = displayfile.read()
session.print content
rescue Errno::ENOENT
session.print "File not found"
end
session.close
end
end
def create_server(args)
command = args[0]
#default port is going to be 3333
port = 3333
#default address will be localhost
address = "localhost"
port = args[1] if args[0].instance_of? String and args[0].eql? "p"
puts "Server created at #{address} and port #{port}"
TCPServer.new address, port
end
def trim_request(request)
request.gsub(/GET\ \//, '').gsub(/\ HTTP.*/, '')
end
def find_file(path)
basepath = "./app/"
if path.empty?
full_path = basepath + 'index.html'
else
full_path = basepath + path
end
File.open full_path, 'r'
end
私が実行しているhtml。これは /app/index.html にあります。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="js/application.js"></script>
<title>CSS-Test</title>
<link type="text/css" href="css/application.css" rel="stylesheet"></link>
</head>
<body>
<h1>CSS-Test</h1>
<div id="box-one">
<p>This is box one.</p>
</div>
<div id="box-two">
<p>This is box two.</p>
</div>
</body>
</html>
私が実行しようとしているcss。/app/css/application.css にあります
.someclass {
background: blue;
}
* {
background: black;
}
編集: css ファイルの場所が間違っていました。