2014-03-01 269 views
0

我使用IE(Internet Explorer)条件注释来修复IE上的保证金问题,但由于某种原因,它不工作,我无法修复它。IE条件注释不起作用

CSS代码(嵌入在条件注释):对于所有其他浏览器

<!--[if IE]> 
    <style> 
.right_header_form{ 
    float: right; 
    margin: -360px 50px 0; 
    width: 240px; 
    height: auto; 
    color: #FFF; 
    font-size: 14px; 
    font-weight: bold; 
    line-height: 21px; 
    padding: 0px; 
    background-color: #444; 
    color: #FFF; 
    border-top-left-radius: 4px; 
    border-top-right-radius: 4px; 
    padding: 10px 15px; 
} 
.right_form { 
    float: right; 
    margin: -320px 50px 0; 
    width: 240px; 
    height: auto; 
    background-color: #F5F5F5; 
    color: #666; 
    margin-bottom: 20px; 
    padding: 15px; 
    border-bottom-left-radius: 4px; 
    border-bottom-right-radius: 4px; 
} 
    </style> 
<![endif]--> 

我原来的CSS代码:

.right_header_form{ 
    float: right; 
    margin: -390px 50px 0; 
    width: 240px; 
    height: auto; 
    color: #FFF; 
    font-size: 14px; 
    font-weight: bold; 
    line-height: 21px; 
    padding: 0px; 
    background-color: #444; 
    color: #FFF; 
    border-top-left-radius: 4px; 
    border-top-right-radius: 4px; 
    padding: 10px 15px; 
} 
.right_form { 
    float: right; 
    margin: -350px 50px 0; 
    width: 240px; 
    height: auto; 
    background-color: #F5F5F5; 
    color: #666; 
    margin-bottom: 20px; 
    padding: 15px; 
    border-bottom-left-radius: 4px; 
    border-bottom-right-radius: 4px; 
} 

正如你所看到的,保证金是每个代码之间的不同其他。正如我所说,它不起作用,但似乎代码是有效的。

问:如何仅使用条件注释更改IE的CSS代码?

+0

@NiettheDarkAbsol嗯,我用了保证金,所以这是IE浏览器有点问题。 – Yotam

+2

IE的哪个版本。 IE11无法识别条件注释。 –

+2

我想这可能是因为添加填充和宽度到同一个容器。 IE使用不同的框模型:http://www.456bereastreet.com/archive/200612/internet_explorer_and_the_css_box_model/ – JohanVdR

回答

0
<!--[if IE]> 
     <style> 
      .right_header_form{ 
       margin: 20px 0 0; 
      } 
      .right_form { 
       margin: 20px 0 0; 
      } 
     </style> 
    <![endif]--> 
    <link rel="stylesheet" href="css/style.css" type="text/css" /> 

检查您的来自mediafire的PHP代码。
您的IE浏览器样式将被覆盖,因为IE条件代码中的第一个。应该是第一个style.css。 CSS优先。

应该是:

<link rel="stylesheet" href="css/style.css" type="text/css" /> 
    <!--[if IE]> 
     <style> 
      .right_header_form{ 
       margin: 20px 0 0; 
      } 
      .right_form { 
       margin: 20px 0 0; 
      } 
     </style> 
    <![endif]--> 
+0

它没有改变一件事,在Firefox的工作,但IE没有。 – Yotam

+0

你的html也有一个错误。 alt属性是图像所必需的。 – JohanVdR

+0

@Sigma:这不是一个“错误”,因为HTML没有真正的错误;它不应该影响这个问题。但是,当然省略'alt'是非标准的。 – rvighne

0

问题是

margin: -390px 50px 0; 

基本上,你猜的.main_form高度390px,所以你让.right_header_form390px向上。

这很糟糕。

编码页面之前,你必须考虑一个好的设计。

在这种情况下,制作两列并将它们放置在其他旁边,将第一个(和第二个可选)浮动。并将标题放在每列中。

0

请注意,条件注释仅适用于INTERNET EXPLORER 9和LOWER,从IE10开始并且它已被禁用。

我的建议是,你把你的IE浏览器CSS在另一个叫iestyle.css CSS文件,并调用它像这样:

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

这有工作,

好运。

PS:也

可以使用条件注释在HTML不同的CSS类或ID适用于元素,你可以接着用CSS目标。

作品是这样的:

<!--[if IE]> 
    <div id="content" class="ie"> 
<![endif]--> 
<!--[if !IE]> 
    <div id="content"> 
<![endif]--> 

这样做是为IE它增加了您在CSS中指定,当它是不是IE !IE它不添加类的类“即”。