我包括一個備用樣式表爲iPhone/iTouch設備。起初,我想簡單地使用handheld
媒體類型:如何讓桌面瀏覽器忽略iPhone css3媒體查詢
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='/css/homepage_handheld.xsl' media='handheld'?>
<?xml-stylesheet type='text/xsl' href='/css/homepage.xsl' media='all'?>
我添加到正是如此DOM文檔:
//Add handheld stylesheet
ProcessingInstruction pi = doc.CreateProcessingInstruction("xml-stylesheet", "type='text/xsl' href='/css/homepage_handheld.xsl' media='handheld'");
doc.InsertBefore(pi, doc.DocumentElement);
//Default css, for everyone else
pi = doc.CreateProcessingInstruction("xml-stylesheet", "type='text/xsl' href='/css/homepage.xsl' media='all'");
doc.InsertBefore(pi, doc.DocumentElement);
不幸的是,iPhone的的Safari的瀏覽器不支持handheld
媒體類型。蘋果提出的解決方法是使用一個CSS3媒體查詢,免去handheld
:
media='handheld'
與檢測iPhone- 像設備的查詢:
media="only screen and (max-device-width: 480px)"
注: 480像素的翻轉iPhone的寬度(即風景)
所以我包括這種媒體類型在我的樣式錶鏈接:
//Add handheld stylesheet
ProcessingInstruction pi = doc.CreateProcessingInstruction("xml-stylesheet", "type='text/xsl' href='/css/homepage_handheld.xsl' media='handheld'");
doc.InsertBefore(pi, doc.DocumentElement);
//BUG: iPhone doesn't support handheld media type. Use the CSS3 media query hack
pi = doc.CreateProcessingInstruction("xml-stylesheet", "type='text/xsl' href='/css/homepage_handheld.xsl' media='only screen and (max-device-width: 480px)'");
doc.InsertBefore(pi, doc.DocumentElement);
//Default css, for everyone else
pi = doc.CreateProcessingInstruction("xml-stylesheet", "type='text/xsl' href='/css/homepage.xsl' media='all'");
doc.InsertBefore(pi, doc.DocumentElement);
這給XML:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='/css/homepage_handheld.xsl' media='handheld'?>
<?xml-stylesheet type='text/xsl' href='/css/homepage_handheld.xsl' media='only screen and (max-device-width: 480px)'?>
<?xml-stylesheet type='text/xsl' href='/css/homepage.xsl' media='all'?>
和所有似乎是好的,但現在瀏覽器(IE8,Chrome5)開始使用 「手持式」 XSL。
「瀏覽器」。
注:火狐(3.5)不支持渲染
xml
內容與xml-stylesheet
可言。這是什麼原因我 不包括它在 「瀏覽器」列表中。
我已經試過移動 「所有」 樣式的iPhone專用媒體查詢以上節點:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='/css/homepage_handheld.xsl' media='handheld'?>
<?xml-stylesheet type='text/xsl' href='/css/homepage.xsl' media='all'?>
<?xml-stylesheet type='text/xsl' href='/css/homepage_handheld.xsl' media='only screen and (max-device-width: 480px)'?>
但即和鉻繼續使用only screen and (max-device-wisth: 480px)
媒體類型。
怎樣纔可以有一個樣式表申請手持,另一個申請「其他人」。