Kairyou's Blog

专注于WEB前端开发, 追求更好的用户体验, 更好的开发体验 [长沙前端QQ群:234746733]
  • CSS HACK 整理

    / 分类: 开发 / No Comments

    HACK1:[php]
    #example {
    margin:5px!important; /* for Firefox */
    margin:10px; /* for IE6 */
    margin /**/:11px; /* for IE5 */
    }
    *+html #example{margin:15px!important; }/* for IE7 */[/php]
    说明:!important声明可以提升指定样式规则的应用优先权。上面“for Firefox” 有“!important”,“for IE7” 也要加“!important”,否则实际出来后IE7依然使用第一个maring值5px。
    HACK2:[php]
    #example {margin:5px; }/* for Firefox */
    * html #example {margin:10px;} /* for IE6 */
    *+html #abc{margin:15px!important;} /* for IE7 */[/php]
    说明:“for IE7”要加“!important”,“+html”能被ie7与ie5.01所识别,但ie5.01不识别important,所以*+html 再加!important 才只能被ie7识别。
    HACK3:[php]
    #example {
    margin:5px; /* For Firefox */
    *margin:10px; /* For IE7 & IE6*/
    _margin:15px; /* For IE6*/
    }[/php]
    说明:这样写CSS文件无法通过验证,但是代码可以写的比较少。
    HACK4:使用IE专用的条件注释[php]
    <!--其他浏览器 -->
    <link rel="stylesheet" type="text/css" href="css.css" />
    <!--[if IE 7]>
    <!-- 适合于IE7 -->
    <link rel="stylesheet" type="text/css" href="ie7.css" />
    <![endif]-->
    <!--[if lte IE 6]>
    <!-- 适合于IE6及以下 -->
    <link rel="stylesheet" type="text/css" href="ie.css" />
    <![endif]-->[/php]
    说明:条件注释的语法:
    [*]gt /Greater than/大于/<!--[if gt IE 5.5]>
    [*]gte /Greater than or equal to/大于等于/<!--[if gte IE 5.5]>
    [*]lt /Less than/小于/<!--[if lt IE 5.5]>
    [*]lte /Less than or equal to/小于等于/<!--[if lte IE 5.5]>
    [*]! /Note/不等于/<!--[if !IE 5.5]>        
    HACK5:[php]
    example{
    margin: 5px;/*FF*/
    >margin: 10px;/*IE5*/
    }
    example/*IE5.5 */{
    >/*IE only*/margin: 15px;/*IE6*/
    >/*IE only*/margin /*IE5.5*/: 20px;
    }[/php]
    说明:“margin”定义的顺序不能改变,即FF-IE5-IE6-IE5.5。对于IE的定义在属性前要加“>”,因为“example/**/{}”这个HACK在FF中可以识别。

  • Sablog-X Hack:字体大中小选择 for1.6

    / 分类: 开发,实践 / No Comments

    之前妹妹曾经对我说BLOG字体太小了,只是当时没心思去改,不过这件事到还放在心上~因为这个意见是的确不错的。把用户体验放首位,做站的都应该知道,而这个字体大小选择也就是其中的一小方面吧。。修改方法比较简单,没什么技术含量,就是用javascript。提供2种方法,都能够支持IE及Firefox、opera等浏览器。

    方法一:编辑模板目录下的show.php

    1.查找:ajax.js"></script>,下面加:

    JavaScript代码
    1. <script language="javascript" type="text/javascript">
    2.     function FontZoom(fsize){
    3.         var ctext = document.getElementById("sa_content");
    4.         ctext.style.fontSize = fsize +"px";
    5.     }
    6. </script>

    2.查找:$article[cname]</a>,后面加:

    XML/HTML代码
    1. 字体:[<a href='javascript:FontZoom(16)'></a> <a href='javascript:FontZoom(14)'></a> <a href='javascript:FontZoom(12)'></a>]  
    3.查找<div class="content">修改为:<div class="content" id="sa_content">

    方法二:编辑模板目录下的show.php

    1.查找:ajax.js"></script>,下面加:

    JavaScript代码
    1. <script language="javascript" type="text/javascript">   
    2. //更改字体大小  
    3. var curfontsize=14;   
    4. function fontZoomA(){   
    5.   if(curfontsize>8){   
    6.     document.getElementById('sa_content').style.fontSize=(--curfontsize)+'pt';   
    7.   }   
    8. }   
    9. function fontZoomB(){   
    10.   if(curfontsize<20){   
    11.     document.getElementById('sa_content').style.fontSize=(++curfontsize)+'pt';   
    12.   }   
    13. }   
    14. </script>      

    2.查找:$article[cname]</a>,后面加:

    XML/HTML代码
    1. 字体:<a href="javascript:fontZoomB();"></a>  <a href="javascript:fontZoomA();"></a>  

    3.同方法一的第3步。