简体   繁体   English

如何仅为IE应用CSS样式

[英]How to apply css styles for IE only

I am trying to fix issues that I am having with how my site is displayed in Internet Explorer. 我正在尝试修复我在Internet Explorer中显示我的网站的问题。 When searching the internet I cam across the following code to use in order to apply CSS styles for IE only. 在搜索互联网时,我会浏览以下代码,以便仅为IE应用CSS样式。 I have attached 2 images, 1 of the site in IE (tel no, menu not displayed correctly), 2nd the site in Firefox and how it should be displayed. 我已经附加了2个图像,1个网站在IE中(电话号码,菜单没有正确显示),第2个站点在Firefox中以及它应该如何显示。

在此输入图像描述 在IE中的网站

I am currently going through the site to try and fix these issues but wanted some advice in order to make sure I'm applying the right code so that this displays correctly in all IE versions and doesn't mess up anything on the browsers. 我目前正在浏览网站尝试修复这些问题,但想要一些建议,以确保我正在应用正确的代码,以便在所有IE版本中正确显示,并且不会弄乱浏览器上的任何内容。

Ideally need some help to display menu and tel no correctly. 理想情况下需要一些帮助才能正确显示菜单和电话。 Currently I have applied the following code to my stylesheet, which has added the correct spacing from the logo and menu, but menu still appears in 2 lines. 目前我已将以下代码应用于我的样式表,该样式表在徽标和菜单中添加了正确的间距,但菜单仍显示在2行中。

my css: 我的css:

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {

#blue {
    width: 31px;
    height: 52px;
    float: left;
    position: relative;
    padding: 15px 0 0 420px;
}

.brand {
    width:261px;   
  }  

  .header-search {
    width:679px;
  }

.icemegamenu > ul > li  a.iceMenuTitle {
    padding: 1px 5px 0 5px;
  }

The site itself can be viewed at http://www.leicesterbakery.co.uk 该网站本身可以在http://www.leicesterbakery.co.uk查看

Would appreciate any advice to fix this. 非常感谢任何解决这个问题的建议。

Thanks in advance. 提前致谢。

UPDATE UPDATE

I have managed to write the following CSS code which fixes the issues I am having for a desktop screen size. 我已设法编写以下CSS代码,修复了我对桌面屏幕大小的问题。 Unfortunately this breaks my code for the responsive side as with this code in the stylesheet, when I resize screen size in any browser like firefox this doesnt show up properly. 不幸的是,这样在响应方面的代码就像样式表中的代码一样,当我在任何像Firefox这样的浏览器中调整屏幕大小时,这并没有正确显示。

Any ideas how i can fix this. 我有什么想法可以解决这个问题。

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {

.body .container {
  padding: 10px 9px;
  }

.brand {
    width:221px;   
  } 

.brand img {
    max-width:90%; 
    padding-top:10px;
  }

.icemegamenu > ul > li  a.iceMenuTitle {
    padding: 1px 23px 0 23px;
  }

Ok I have managed to sort out the issue with the responsive code by adding (min-width:980px) to my media tag for IE. 好的,我已经设法通过向IE的媒体标签添加(min-width:980px)来解决响应代码的问题。 Last issue is to align the tel no on both IE and firefox to the right of the page... any advice would be greatly appreciated. 最后一个问题是将IE和Firefox上的tel no对齐到页面右侧...任何建议都将非常感谢。

我减少了#blue div上的左边距,这似乎得到了一行的数字。

If you want a special CSS for IE only you can do it like this: 如果你想要一个特殊的IE浏览器,你可以这样做:

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

and you can add the version of IE like this: 你可以像这样添加IE的版本:

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

or if you want to just use one style, check this link for 或者如果您只想使用一种风格,请查看此链接

references: https://css-tricks.com/how-to-create-an-ie-only-stylesheet/ 参考: https//css-tricks.com/how-to-create-an-ie-only-stylesheet/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM