2017-08-04 25 views
0

我在不同的文件上有兩個css ID,並且只有當程序在Internet Explorer中執行時,我才必須用另一個文件更改文件。 我有這個文件稱爲「custom.css」:如何爲我的.cshtml MasterPage添加條件註釋?

#employee-list { 
    border-bottom: 1px solid #c1c1c1; 
    border-top: 1px solid #c1c1c1; 
    height: initial; 
} 

我需要(我不能修改custom.css)設置「高度」爲「自動」。但只限於在IE上呈現頁面。所以,我創建了一個名爲「customie.css」第二css文件:

#employee-list { 
    border-bottom: 1px solid #c1c1c1; 
    border-top: 1px solid #c1c1c1; 
    height: auto; 
} 

後,我寫了我的母版.cshtml的<head>這個條件註釋。

<!--[if IE]> 
    <link rel="stylesheet" type="text/css" href="customie.css" /> 
<![endif]--> 

問題是這樣的:條件註釋不工作和customie.css文件將覆蓋custom.css(其中撤銷本級本身)。 我如何才能將height: auto僅用於IE頁面?

謝謝 安傑洛

+1

的可能的複製[<! - \ [如果IE \]!>不工作(https://stackoverflow.com/questions/13785587/if-ie-not-working) – Hackerman

回答

0

不知道爲什麼條件不工作,但你可以使用下面的CSS達到預期的效果。 IE不支持initial,所以它會回落到auto

#employee-list { 
    border-bottom: 1px solid #c1c1c1; 
    border-top: 1px solid #c1c1c1; 
    height: auto; 
    height: initial; 
} 
+0

它的工作原理!謝謝馬丁! –