基本上,我想知道如果這個代碼是好的,我可以在開始標記中包含IE條件註釋嗎?
<body id="some_id" <!--[if lt IE 7 ]>class="ie6"<![endif]--> >
</body>
基本上,我想知道如果這個代碼是好的,我可以在開始標記中包含IE條件註釋嗎?
<body id="some_id" <!--[if lt IE 7 ]>class="ie6"<![endif]--> >
</body>
號HTML註釋不能是一個標籤內。請嘗試:
<!--[if gte IE 7]>--> <body id="some_id"> <!--<![endif]-->
<!--[if lt IE 7]> <body id="some_id" class="ie6"> <![endif]-->
否 - 無法在標籤內插入註釋。
不,沒有必要。總是給全班body元素並保留CSS .ie
定義爲空所有的瀏覽器IE6,但是:
.ie6 {
<!--[if lt IE 7]-->
... ugly ie6 hack ...
<!--[endif]-->
}
</style>
<body class="ie6">
不錯的想法,但這限制了我的一個版本,即在類 如果我想在未來添加ie7或ie8類,我不知道這是否是最好的解決方案 – mjr 2010-08-20 14:48:35
爲什麼?您可以根據需要將多個類添加到單個元素中(用空格分隔),也可以使用'ie'作爲泛型類,然後在CSS中放置大量if。 – 2010-08-23 07:48:06
,你不行,所以你將不得不重複的標籤及其所有屬性。
很多人在<html>
標記中添加瀏覽器標識符類。使用body
標籤也很好,但我會使用哪個標籤的屬性中包含最少量的字符。
WordPress的「身體」的標籤可能看起來像這樣
<body class="home page page-id-38 page-template page-template-template-homepage page-template-template-homepage-php woocommerce-demo-store storefront-full-width-content right-sidebar woocommerce-active has-site-logo">
所以你會把類的<html>
標籤,從而省卻了重複那長長的一串。
<!DOCTYPE html>
<!--[if lt IE 7 ]> <html class="ie6"<![endif]-->
<!--[if IE 7 ]> <html class="ie7"<![endif]-->
<!--[if IE 8 ]> <html class="ie8"<![endif]-->
<!--[if IE 9 ]> <html class="ie9"<![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html> <!--<![endif]-->
<head>
</head>
<body class="home page page-id-38 page-template page-template-template-homepage page-template-template-homepage-php woocommerce-demo-store storefront-full-width-content right-sidebar woocommerce-active has-site-logo">
A html
標記可能看起來像這樣。
<html class="" lang="en" xml:lang="en" dir="ltr" prefix="og: http://ogp.me/ns#" itemscope itemtype="http://schema.org/Webpage">
在這種情況下,你可能把類的<body>
標籤。
<!DOCTYPE html>
<html lang="en" xml:lang="en" dir="ltr" prefix="og: http://ogp.me/ns#" itemscope itemtype="http://schema.org/Webpage">
<head>
</head>
<!--[if lt IE 7 ]> <body class="ie6"><![endif]-->
<!--[if IE 7 ]> <body class="ie7"><![endif]-->
<!--[if IE 8 ]> <body class="ie8"><![endif]-->
<!--[if IE 9 ]> <body class="ie9"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <body> <!--<![endif]-->
如果我有什麼讓我不喜歡,而是多次重複一個巨大的字符串,就像這樣。
<!DOCTYPE html>
<html class="" lang="en" xml:lang="en" dir="ltr" prefix="og: http://ogp.me/ns#" itemscope itemtype="http://schema.org/Webpage">
<head>
</head>
<body class="home page page-id-38 page-template page-template-template-homepage page-template-template-homepage-php woocommerce-demo-store storefront-full-width-content right-sidebar woocommerce-active has-site-logo">
然後我可能會使用JavaScript
<!DOCTYPE html>
<html class="" lang="en" xml:lang="en" dir="ltr" prefix="og: http://ogp.me/ns#" itemscope itemtype="http://schema.org/Webpage">
<head>
<script>
(function(){
var d=document,
h=d.documentElement,
v = 3,
p = d.createElement('p'),
i = p.getElementsByTagName('i'),
u;
while (
p.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
i[0]
);
h.className += (v > 4 ? ' ie'+v : '');
})()
</script>
</head>
<body class="home page page-id-38 page-template page-template-template-homepage page-template-template-homepage-php woocommerce-demo-store storefront-full-width-content right-sidebar woocommerce-active has-site-logo">
此腳本James Padolsey's腳本,它增加了類的html
標籤的修飾的版本。
謝謝,我的麻煩是,身體可能會或可能不會有一個ID取決於服務器端腳本,看起來像我必須找到另一個解決方案 – mjr 2010-08-20 14:49:52
@ mjr爲什麼不讓服務器端腳本處理它呢? – 2010-08-20 14:51:21
ya ...我不熟悉服務器端的瀏覽器嗅探 – mjr 2010-08-20 14:54:26