Drupal建站,CSS Hacker Tip

对于drupal的大名,早敬仰已久。这套开源一直已思路奇特而巧妙著称。

如果说DEDE这样的国产代码是用来对付大陆客户、完成任务的。
那么drupal、wordpress这类西洋经典,则是用来欣赏、品味的。当然玩好了之后,对于土客户和洋客户更是威力无穷。

难得借着重建公司网站的机会,自己亲手定制一把。果然象大家告诫的一样“上手很头疼”。不过经过两三周断断续续的研究,估计技术问题已经解决掉一半了。眼看着大概模样逐渐成形,心里挺高兴。

另,转两篇CSS hacker技巧。省得每次都现查。
CSS Tip: Targeting IE 5.x, 6 and 7 Separately,Conditional comments。

CSS Tip: Targeting IE 5.x, 6 and 7 Separately

In rare situations it may be necessary to provide different rules, not only to the Internet Explorer family in general, but also to each individual version. We can combine 3 CSS Hacks to achieve this.
Differentiating between IE 6 and below and IE 7

Firstly we can target IE 6 and IE 7 separately using the underscore hack and far less well documented star property hack (commonly mistaken for the star HTML hack).

.box {
   background: #00f; /* all browsers including Mac IE */
   *background: #f00; /* IE 7 and below */
   _background: #f60; /* IE 6 and below */
   padding: 7px;
   color: #fff;
}

View Example

In this example all non IE browsers (which also includes Mac IE) see the first background rule. This sets the box colour to blue. Both IE 6 & 7 then see the next rule (prefixed with a star) which overrides the first rule and sets the background colour to red. Finally IE 6 and below also see the final rule (prefixed with an underscore) and set the background colour to orange.

Differentiating between IE 6 and IE 5.x

We can expand on this ruleset by making use of the backslash part of the Simplified Box Model Hack described here. Escaping any letter within the property name which isn’t in the range a-f, A-F, 0-9 will hide that rule from IE 5.x. We can therefore define a rule for IE 5.x, which will also be seen by IE 6, and then override that with a backslash commented rule for IE 6.

.box {
   background: #00f; /* all browsers including Mac IE */
   *background: #f00; /* IE 7 and below */
   _background: #0f0; /* IE 6 and below */
   _bac\kground: #f60; /* IE 6 only */
   padding: 7px;
   color: #fff;
}

View Example

The background colour in IE 5.x will now be green rather than the orange specified for IE 6.
Conditional Comments

Of course IE already provides the ability to target different versions via conditional comments. You should generally favour these over the method described above. There are, however, situations where you may want to consider it, such as when the scope of changes are so small that you don’t want to incur the overhead of an additional HTTP request if included in an external file or if don’t want to include the IE specific rules inline.
Disclaimer

You should always be careful when implementing CSS hacks and first make sure that the problem you’re trying to solve is in fact something that needs hacking around and not something you’ve implemented incorrectly. Tantek Çelik article on the Web Standards Project Website provides interesting reading on the history of hacks and when and when not to use them.

    * Back to index
    * Bookmark It

Comments

    *

      Nice hack, you can take this a step further for IE 5.0, and IE 5.5 by using comments in your rules. So your example would be:

      .box {
         background: #00f; /* all browsers including Mac IE */
         *background: #f00; /* IE 7 and below */
         _background/**/: #0f0; /* IE 5.0 */
         _background:/**/ #f62; /* IE 5.5 only */
         _background/**/:/**/ #f61; /* IE 6 only */
         padding: 7px;
         color: #fff;
      }

From: http://www.ejeliot.com/blog/63


Conditional comments

<p><!--&#91;if IE&#93;>
According to the conditional comment this is Internet Explorer
<!&#91;endif&#93;-->
<!--&#91;if IE 5&#93;>
According to the conditional comment this is Internet Explorer 5
<!&#91;endif&#93;-->
<!--&#91;if IE 5.0&#93;>
According to the conditional comment this is Internet Explorer 5.0
<!&#91;endif&#93;-->
<!--&#91;if IE 5.5&#93;>
According to the conditional comment this is Internet Explorer 5.5
<!&#91;endif&#93;-->
<!--&#91;if IE 6&#93;>
According to the conditional comment this is Internet Explorer 6
<!&#91;endif&#93;-->
<!--&#91;if IE 7&#93;>
According to the conditional comment this is Internet Explorer 7
<!&#91;endif&#93;-->
<!--&#91;if gte IE 5&#93;>
According to the conditional comment this is Internet Explorer 5 and up
<!&#91;endif&#93;-->
<!--&#91;if lt IE 6&#93;>
According to the conditional comment this is Internet Explorer lower than 6
<!&#91;endif&#93;-->
<!--&#91;if lte IE 5.5&#93;>
According to the conditional comment this is Internet Explorer lower or equal to 5.5
<!&#91;endif&#93;-->
<!--&#91;if gt IE 6&#93;>
According to the conditional comment this is Internet Explorer greater than 6
<!&#91;endif&#93;-->
</p>

Note the special syntax:

    * gt: greater than
    * lte: less than or equal to

from: http://www.quirksmode.org/css/condcom.html

最后抱怨一句,IE算啥破完艺儿啊,每个版本显示都不一样。

《Drupal建站,CSS Hacker Tip》上有0条评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Time limit is exhausted. Please reload CAPTCHA.