在 Firefox 中显示图像地图需要内联 CSS 吗?
我已经使用 CSS 包含了一个图像映射(如这篇相当旧的 2004 年文章中所述) >A List Apart)位于外部托管的Facebook iframe 页面。我正在使用带有 a:link/a:hover 图像的图像映射,CSS 包含在外部样式表中。该页面在 Safari 和 Chrome 中正确显示,但 在 Mac OS X 上的 Firefox 3.6 中无法正确显示。
如果我切换回内联样式,页面在 Firefox 中正常显示。
以下是内联应用样式的代码:
<style type="text/css">
#home-page-nav {
width: 512px; height: 139px;
background: url(http://mysite.com/imagemap.jpg);
margin: 10px auto; padding: 0;
position: relative;}
#home-page-nav li {
margin: 0; padding: 0; list-style: none;
position: absolute; top: 0;}
#home-page-nav li, #home-page-nav a {
height: 141px; display: block;}
#blog-icon {left: 0; width: 127px;}
#links-icon {left: 128px; width: 128px;}
#twitter-icon {left: 256px; width: 128px;}
#flickr-icon {left: 384px; width: 128px;}
#blog-icon a:hover {
background: transparent url(http://mysite.com/imagemap.jpg)
0 -139px no-repeat;}
#links-icon a:hover {
background: transparent url(http://mysite.com/imagemap.jpg)
-128px -139px no-repeat;}
#twitter-icon a:hover {
background: transparent url(http://mysite.com/imagemap.jpg)
-256px -139px no-repeat;}
#flickr-icon a:hover {
background: transparent url(http://mysite.com/imagemap.jpg)
-384px -139px no-repeat;}
</style>
<ul id="home-page-nav">
<li id="blog-icon"><a href="http://donaldjenkins.net/"></a></li>
<li id="links-icon"><a href="http://links.donaldjenkins.net/"></a></li>
<li id="twitter-icon"><a href="http://twitter.com/donaldjenkins"></a></li>
<li id="flickr-icon"><a href="http://flickr.com/photos/astorg"></a></li>
</ul>
欢迎提出有关解决此问题的任何建议。
更新:感谢下面的尼尔找到了解决方案。以防万一其他人也遇到同样的问题,以下是解决方法。解决方案是更新托管 CSS 文件的 Web 服务器的配置。某些 Apache 和 iPlanet Web 服务器将具有 .CSS 的文件与不正确的 MIME 类型(例如“text/plain”或“application/x-pointplus”)相关联。在某些情况下,Netscape 7.x 和 Mozilla 会忽略 CSS 文件,因为它的 MIME 类型错误,并使用默认样式表,导致布局与 Web 开发人员的预期不同。有关更多详细信息,请参阅 Mozilla 开发网络上的此页面。
解决此问题的最简单方法是在 .htaccess 文件中包含以下行:
AddType text/css .css
I've included an image map using CSS (as described in this rather old 2004 article in A List Apart) in an externally-hosted a Facebook iframe page. I'm using an image map with images for a:link/a:hover, with the CSS included in an external stylesheet. The page displays correctly in Safari and Chrome, but not in Firefox 3.6 on Mac OS X.
If I switch back to inline styles, the page displays properly in Firefox.
Here's the code with the styles applied inline:
<style type="text/css">
#home-page-nav {
width: 512px; height: 139px;
background: url(http://mysite.com/imagemap.jpg);
margin: 10px auto; padding: 0;
position: relative;}
#home-page-nav li {
margin: 0; padding: 0; list-style: none;
position: absolute; top: 0;}
#home-page-nav li, #home-page-nav a {
height: 141px; display: block;}
#blog-icon {left: 0; width: 127px;}
#links-icon {left: 128px; width: 128px;}
#twitter-icon {left: 256px; width: 128px;}
#flickr-icon {left: 384px; width: 128px;}
#blog-icon a:hover {
background: transparent url(http://mysite.com/imagemap.jpg)
0 -139px no-repeat;}
#links-icon a:hover {
background: transparent url(http://mysite.com/imagemap.jpg)
-128px -139px no-repeat;}
#twitter-icon a:hover {
background: transparent url(http://mysite.com/imagemap.jpg)
-256px -139px no-repeat;}
#flickr-icon a:hover {
background: transparent url(http://mysite.com/imagemap.jpg)
-384px -139px no-repeat;}
</style>
<ul id="home-page-nav">
<li id="blog-icon"><a href="http://donaldjenkins.net/"></a></li>
<li id="links-icon"><a href="http://links.donaldjenkins.net/"></a></li>
<li id="twitter-icon"><a href="http://twitter.com/donaldjenkins"></a></li>
<li id="flickr-icon"><a href="http://flickr.com/photos/astorg"></a></li>
</ul>
Any suggestions as to solving this welcome.
UPDATE: The solution was found thanks to Neil below. Just in case anyone else has the same issue, here's how to fix it. The solution is to update the configuration of the web server hosting the CSS file. Some Apache and iPlanet web servers are associating files having a .CSS with an incorrect MIME-type such as "text/plain" or "application/x-pointplus". In some cases, Netscape 7.x and Mozilla ignore the CSS file because of its wrong MIME type and use a default style sheet that causes the layout to be different from what was intended by the web developer. See this page on the Mozilla Development Network for more details.
The simplest way to solve it is by including the following line in your .htaccess file:
AddType text/css .css
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为一项安全功能,外部样式表必须使用
text/css
MIME 类型提供,否则 Firefox 将忽略它们。As a security feature, external stylesheets must be served with the
text/css
MIME type, otherwise they will be ignored by Firefox.