发新话题
打印

个人使用css的一点经验,现在贴出来,给大家参考下

个人使用css的一点经验,现在贴出来,给大家参考下

前几天,一朋友说他要公司里的人培训css,让我写一份类似的东西给他,现在我把他贴出来,供大家参考下
样式我也不是用的特别好,希望大家看了后别对我大喷口水 ,大家一起学习.


1、将公用的css表独立成单独文件(即每个页面都要使用到这些样式效果),这样可以提高样式的使用效率

(
建议这个独立文件名为 global.css)
比如:
body,td,th {font-size: 12px; font-family:Arial, Helvetica, sans-serif}
body {margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px;}
a:link {text-decoration: none;}
a:visited {text-decoration: none;}
a:hover {text-decoration: underline;}
a:active {text-decoration: none;}
可以放在这个独立文件中

调用这个文件可以是用
<link href="../Style/Index.css" rel="stylesheet" type="text/css">
或直接放在样式文件
<style type="text/css">
<!--
@import url("sitefiles/localhost/Style/top.css");
@import url("sitefiles/localhost/Style/index.css");
-->
</style>

2、强制换行
#wrap{word-break:break-all; width:200px;}
       注:#wrap.wrap的区别在于,#对应的是id.对应的是.class
Id是在使用js效果的时候用的比较经常,建议在定义大块时,使用id,使用小块时用.class
例如:
<style type="text/css">
<!--
#wrap{word-break:break-all; width:200px;}
.wrap1{word-break:break-all; width:200px;}
-->
</style>
<div id=’wrap’>aaaaa</div>
<div class=’wrap1’ >bbbbb</div>


3、左右两边对起

.justify{text-align:justify;text-justify : }

4float的使用

Float
浮动看www.zhong-design.com 的使用
5float结合li的使用
       以个人的使用经验来说,我在使用这个的比较多的是在导航的制作,
www.zhong-design.com 为例子,他的导航的效果
<div class=’menu’>
<ul>
<li>aaaa</li>
<li>aaaa</li>
<li>aaaa</li>
</ul>
</div>
<div class=’clear’></div>
<style type="text/css">
<!--
.menu{width:200px; margin-top:10px; margin-right:10px; margin-buttom:10px; margin-left:10px;
}

.menu ul{ margin:0; padding:0; list-style-type:none }
.menu ul li{width:99px; margin-right:1px; color:#ff0000; background:#000; float:left}
.clear{clear:both}/*使用完float必须清除浮动,否则在其他浏览器的下会出现结构混乱的情况*/
-->
</style>
margin-top:10px; margin-right:10px; margin-buttom:10px; margin-left:10px;这段可以简写成margin:10px 或者margin:10px 10px 10px 10px(规则:上右下左)
padding类似用法
margin对应的是块的外边,padding对应的是块的内容
例如:
<div class=’info’></div>
<style type="text/css">
<!--
.menu{width:200px; margin:10px; border:1px solid #000; padding:15px}
-->
</style>
实际看到的是,menu的长度230px,所以我们只需要他显示200px的时候,需要减去padding-left:15pxpadding-right:15px 30px
所以.menu{width:2170px; margin:10px; border:1px solid #000; padding:15px}


6、连接样式的定义
例子:
<div class=”Class_Link”><a href=’Index.asp’>**科技</a></div>
.Class_Link{height:24px; line-height:24px; width:100px; text-algin:center}
.Class_Link a{color:ff0000; text-decoration: none;}
.Class_Link a:link{color:ff0000; text-decoration: none;}
.Class_Link a:hover{color:fff; text-decoration: none;}
.Class_Link a:visited {text-decoration: none;}
.Class_Link a:active {text-decoration: none;}

7、浏览器兼容

区别IE6FF:background:orange;*background:blue;

区别IE6IE7: background:green
!important;background:blue;

区别IE7FF:background:orange; *background:green;

区别FFIE7IE6: background:orange;*background:green
!important;*background:blue;

注:IE都能识别*;标准浏览器(如FF)不能识别*;

IE6能识别*,但不能识别 !important,

IE7能识别*,也能识别!important;

FF不能识别*,但能识别!important;

IE6

IE7

FF

*

×

!important

×


另外再补充一个,下划线"_",
IE6
支持下划线,IE7和firefox均不支持下划线。
于是大家还可以这样来区分
IE6IE7firefox
: background:
orange;*background:green;_background:blue;
注:不管是什么方法,书写的顺序都是firefox的写在前面,IE7的写在中间,IE6的写在最后面。



8、超过固定长度隐藏
.overflow {OVERFLOW: hidden; WHITE-SPACE: nowrap; TEXT-OVERFLOW: ellipsis; WIDTH: 278px}
即超文字长度超过278px后,自动隐藏掉,隐藏的信息’…’结束,但是在该功能虽然火狐或者其他浏览器功能还是存在,但是他的’…’还是会显示成隐藏掉的文字
本帖最近评分记录
  • 随风 虚拟币 +5 精品文章 2008-4-3 14:45

TOP

不错不错! 支持原创,应该加积分
会笑的猪为楼主的帖子评分
      会笑的猪   积分  +5  支持原创  2008-4-3 14:55


[ 本帖最后由 会笑的猪 于 2008-4-3 14:59 编辑 ]
声誉好得令人发指,人格闪亮得让人嫉妒!

TOP

哈哈,楼上的,竟然比我慢10秒~~
//爱一个人就是在拔通电话时,忽然不知道说什么好,原来只是想听听那熟悉的声音,原来真正想拔动的只是自已心底深处的一根弦

TOP

恩。。很经典。。。。。
www.girlsgroup.cn

踏踏实实工作。。。。。。本本分分泡女人。。。。。

TOP

恩,很有收获,顶一下

TOP

不错,支持一下了。。。。。。。。






上海seo公司

TOP

不错嘛。。。支持。。。原创一定要支持。。而且还是很不错的原创。。。
夜夜相思更漏残,伤心明月凭阑干,想君思我锦衾寒。咫尺画堂深似海,忆来唯把旧书看,几时携手入长安?

TOP

发新话题