CSS 忽略第一节课后的所有内容
我正在使用 本指南 创建一个 HTTPHandler,它将脚本和 css 文件组合在一起将它们按一份请求交付。
基本上,它会将一堆 .css 文件读取到字节数组中,然后响应。以文本/css(或文本/javascript)内容类型将字节写入客户端。
当使用 FireBug 时,CSS 似乎表现良好。 ..一切都在那里。然而,浏览器本身只会渲染组合操作中使用的第一个文件中的 CSS。
示例:
File1.css: 正文 { 字体大小:20px; } h1 { 颜色:红色;文件
2.css: div { 边框:实心 1px 黑色; 所有CSS
都可以通过 CSS 选项卡中的 Firebug 看到...但是 File2.css 中的类实际上并未应用于页面上的 div。如果我翻转文件的顺序,div 会获得边框,但 File1.css 中的任何内容都不会应用。
Javascript 文件工作得很好,但 CSS 让我完全难住了!
编辑以显示从 Firebug 中复制的 CSS
body {
font-size:22px;
}
h1 {
color:Red;
text-decoration:underline;
}
div {
border:1px solid black;
}
这是来自 NET 选项卡,生成的实际响应
ParamsHeadersPostPutResponseCacheHTML
Response Headersview source
Server ASP.NET Development Server/9.0.0.0
Date Mon, 29 Nov 2010 01:10:26 GMT
X-AspNet-Version 2.0.50727
Transfer-Encoding chunked
Cache-Control public, must-revalidate, proxy-revalidate, max-age=259200
Expires Thu, 02 Dec 2010 01:10:26 GMT
Content-Type text/css
Connection Close
Request Headersview source
Host localhost:49598
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12
Accept text/css,*/*;q=0.1
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
Referer http://localhost:49598/
body
{
font-size: 22px;
}
h1
{
color: Red;
text-decoration: underline;
}div
{
border: solid 1px black;
}
新开发。如果我在记事本中创建 .css 文件,一切正常。 VS2008在创建样式表文件时是否会添加一些看不见的东西到文件中?
FIDDLER TEXTVIEW(不知道额外的字符来自哪里。有趣。
9a
body
{
font-size: 22px;
}
h1
{
color: Red;
text-decoration: underline;
}div
{
border: solid 1px black;
}
0
I'm using this guide to create a HTTPHandler that combines script and css files to deliver them as one request each.
Basically it reads a bunch of .css files into a byte array and then response.writes the bytes to the client with a content-type of text/css(or text/javascript)
When using FireBug it appears that the CSS comes through fine...it is all there. However, the browser itself will is only rendering CSS that is in the first file used in the combining action.
Example:
File1.css:
body { font-size: 20px; }
h1 { color: red; }
File2.css:
div { border: solid 1px black; }
All the CSS is visible via Firebug in the CSS tab...however the class from File2.css is not actually applied to divs on the page. If I flip the order of the files, divs get a border, but nothing from File1.css gets applied.
Javascript files work totally fine, but the CSS has me totally stumped!
EDIT TO SHOW CSS COPIED OUT OF FIREBUG
body {
font-size:22px;
}
h1 {
color:Red;
text-decoration:underline;
}
div {
border:1px solid black;
}
HERE IT IS FROM THE NET TAB, THE ACTUAL RESPONSE GENERATED
ParamsHeadersPostPutResponseCacheHTML
Response Headersview source
Server ASP.NET Development Server/9.0.0.0
Date Mon, 29 Nov 2010 01:10:26 GMT
X-AspNet-Version 2.0.50727
Transfer-Encoding chunked
Cache-Control public, must-revalidate, proxy-revalidate, max-age=259200
Expires Thu, 02 Dec 2010 01:10:26 GMT
Content-Type text/css
Connection Close
Request Headersview source
Host localhost:49598
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12
Accept text/css,*/*;q=0.1
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
Referer http://localhost:49598/
body
{
font-size: 22px;
}
h1
{
color: Red;
text-decoration: underline;
}div
{
border: solid 1px black;
}
New development. If I create the .css files in notepad everything works fine. Does VS2008 add something unseen to the file when creating a Stylesheet file?
FIDDLER TEXTVIEW (Dunno where the extra characters came from. Interesting.
9a
body
{
font-size: 22px;
}
h1
{
color: Red;
text-decoration: underline;
}div
{
border: solid 1px black;
}
0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
GetFileBytes
中将以下行更改为
In the
GetFileBytes
change the following linesTo
我不确定出了什么问题;如果 Firebug 的 CSS 选项卡看到 CSS,则它应该进行渲染。
尝试清除缓存 (Ctrl+F5) 并重新启动 Firefox。
尝试在服务器上的 CSS 文件之间添加换行符;有一点可能会有所帮助。
I'm not sure what's wrong; if Firebug's CSS tab sees the CSS, it ought to render.
Try clearing the cache (Ctrl+F5) and restarting Firefox.
Try adding a newline between the CSS files on the server; there's a slight possibility that that might help.