How to give Internet Explorer different CSS lines?

2019-03-06 00:07发布

Imagine I'm having a DIV. I want to display it in a row with other divs, so I'm giving it display: inline-block along with other style definitions in a CSS sheet.

Now Internet Explorer wants to have display: inline; for the behavior I want.

How do I give Internet Explorer a seperate styling command to overwrite the definition for good browsers, so only IE will have display: inline;. Due to technical limitations I cannot use <![If IE] -->-stuff in HTML, I need to stay within the CSS file.

4条回答
放荡不羁爱自由
2楼-- · 2019-03-06 00:35

A horrible way to do it is: http://www.webdevout.net/css-hacks

Even though you cannot change the HTML I'd read up on http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/

查看更多
该账号已被封号
3楼-- · 2019-03-06 00:39

IE actually has quite good support for inline-block - if the element is originally an inline element. So try using a span instead of the div.

查看更多
对你真心纯属浪费
4楼-- · 2019-03-06 00:40

You can use selectors like so:

\9 – IE8 and below, * – IE7 and below, _ – IE6

So in your case:

*display: inline;

You can simply add this to the rest of the css:

div{
display: inline-block;
// some;
// other;
// css;
*display: inline;
}

Read my blog post on this.

Update

IE version 5 till 8. (They are all affected) – Cobra_Fast 1 min ago

So in this case, you'd use

div{display\9:inline;}
查看更多
倾城 Initia
5楼-- · 2019-03-06 00:46

To make inline-block work on block-level elements in IE7, I frequently add this to my answers:

I sure hope what I'm suggesting everywhere actually works :D

See: http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/

selector {
    display: inline-block;
    *display: inline;
    zoom: 1;
}
查看更多
登录 后发表回答