4
votes

TL;DR

I've read through many questions on Stack Overflow on this issue and I've tried to follow the given advice. Still, my CSS stylesheet will not work in Chrome/Safari but it can work in Internet Explorer.

The only odd thing that I can see about my scenario is my server is returning all files as of type application/octet-stream. I cannot change this aspect of the server. Is there something I can do to interpret my CSS file as a stylesheet in Chrome/Safari and IE?


I have an embedded web server project that I am working on. I have very limited control of the server software and the ability to make page-level settings. All I can do is create static HTML, CSS, and image files that are compiled into the server application.

As such, all files that are returned from the embedded server are declared as application/octet-stream in the HTTP header. This produces warnings in Chrome but no errors.

Initially, I had a problem loading this style sheet in Chrome/Safari but it would work in IE. After reading through a couple questions on Stack Overflow, I found that I needed to change my stylesheet declaration from:

<link rel="stylesheet" href="/styles/index.css">

to:

<link rel="stylesheet" type="text/css" href="/styles/index.css">

When I made this change Chrome & Safari still failed to process the CSS file but IE also started to ignore the stylesheet.

Oddly, if I do not declare a DOCTYPE on my HTML document I can get linked stylesheets to work in all of my browsers. This is, however, not a desirable solution.

My guess is this issue has something to do with the HTTP header declaration and that it doesn't match the type declared in the link element.

What can I do to get this stylesheet to work in Chrome, Safari, and IE while following good web development codes-of-practice (i.e. using doctypes on my HTML files and not embedding the style code in the HTML headers?)

For clarity sake, the relevant CSS/HTML code is shown below.

index.css

html {height:100%}
body {margin:0;min-height:100%;position:relative}
iframe {width:100%;height:100%;border:none}

.hdr {min-width:765px;overflow:auto}
.logo1 {float:left;margin:4px}
.logo2 {float:right;margin:4px}
.menu {position:absolute;top:70px;left:0px;bottom:0px;width:175px}
.content {position:absolute;top:70px;left:175px;bottom:0px;right:0px;}

index.htm

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel="stylesheet" href="/styles/index.css"> <!-- Removed the type declaration so that  this would at least work in IE9 //-->
</head>
<body lang="en-us">
<div class="hdr"><img class="logo1" src="/images/logo1.png" alt="Logo #1"><img class="logo2" src="/images/logo2.png" alt="Logo #2"></div>
<div class="menu"><iframe name="menu" src="/menu.shtm"></iframe></div>
<div class="content"><iframe name="main" src="/home.htm"></iframe></div>
</body>

FYI, this is a new project that is being developed from an existing one. The original project did not declare a DOCTYPE on the HTML files. Therefore, all page data was loaded and executed in the browser in quirks mode. Furthermore, the index.htm originally consisted of multiple frames within a frameset.

I am trying to update this application, using correct, and up to date methods for developing web pages. I can make this application work, but I feel that this would be at a sacrifice of future-browser compatibility if I have to rely on browser quirks mode and framesets.

I have tried to close the link tag but that doesn't help. Technically, this shouldn't be an issue since this document is declared as an HTML5 document, rather than XHTML.

6
Strange, 1st time IE is doing something good and other browsers are notMr. Alien
Try closing your meta and link tags with /> They are currently open. (May aswell do the same with <img>, though that won't affect the questionAndy
@Andy Yes, I'm not having any trouble with my images but I'll try your suggestion.RLH
No, it didn't help. @insertusernamehere, I wanted to give it a try just to be sure but that is why I've left it out.RLH
Where is your CSS file located? Is it in root? Because /styles/index.css will look in the root directory in Chrome, based on my experiments. (Eg. on my Windows box it was looking for C:\styles\index.css.) Once I stuck the CSS file there, it worked fine.Roddy of the Frozen Peas

6 Answers

4
votes

It's certainly due to the application/octet-stream content type. I can re-create the issue on my end. Soon as the content type is set to text/css your HTML/CSS load fine.

As a workaround you can use <style> tags for you CSS if you can't get the server to send the correct content type.

3
votes

I hate to have to answer my own question this way but the problem was most certainly with the fact that the server was returning a content type of application/octet-stream within the HTTP header.

After discussing the issue with management we had to update the code associated with the HTTP processor. This is code that is part of a third-party RTOS and we have been extremely hesitant to making any changes to this code.

However, in this case the need has out-weighed that desire. I've integrated the necessary changes to fix the HTTP header to return a content type of "text/css" for cascading style sheets. All is now right with the world.

3
votes

I think I'll just chime in here. Not to answer the question, but to confirm the issue and perhaps help people with similar problems.

I had the same problem: an external css file was loaded alright, but it was not applied in Chrome. (Safari and FF were ok about it). So, same problem, slightly different cause.

It turned out that because of a bug in the webserver code the HTTP response contained two Content Types, 'text/html' and 'text/css'.

The solution was to remove the faulty 'text/html' line. It seems Chrome is pickier than other browsers about response headers. Which I suppose is legitimate, but a warning would have been nice.

btw, you can see all the http information for a loaded resource in Chrome, when you open Developer Tools, and select Network. Then click on the file that you want to investigate. (it took me a while to find that)

2
votes

We had a problems with an iframe wich it's contents was updated by an external javascript routine, the CSS were loaded but were not applied. But updating the body HTML from a routine present in the iframe head worked as suposed to.

This same behaviour was not present in gecko and explorer, but happened the same at Safari browser (webkit)

Hope this could give some light in this curious case.

0
votes

I would like to add one bit of information that may save some of you some time. It appeared that chrome was not recognizing my CSS either. After reading the above post I reviewed the files in the Developer Tools->Network. Turns out that Chrome was using a locally cached version of my CSS. As soon as I refreshed as opposed to accessing the URL again, it worked!

0
votes

I'm no expert, but i've made this mistake before, it's rather simple.

You've written:

<link rel="stylesheet" href="/styles/index.css">

If this is a folder in the same directory as your index.html file, then you need to remove the first /. like so:

<link rel="stylesheet" href="styles/index.css">

EDIT: I think someone else mentioned this already, but it may have been overlooked.