常用CSS2基本定义例子

80酷酷网    80kuku.com

  css 大部分定义根据项目需求定制,并不适合每个网站,提出一种思路,抛砖引玉。


  • 主要兼容MOZ & IE6。好多年不用IE5.x了,而且也没测试环境,工作和自己项目都已不考虑IE5;
  • 定义名主要采用单字母识别。主要是自己使用,减少代码,语意描述显然不是很好;
  • 大量采用包含选择符增加定义重用,定义写法上重复都为合写,可读性同样不是那么好;
  • 链接部分定义适用于触发不换色,只增加下划线;
  • 欢迎提出意见。可能部分定义对兼容有潜在的影响,个人使用不断更新。


语言定义

常被忽略,但我总喜欢加上charset "gb2312";

全局宏观定义

html,body标签,以及MOZ的模块兼容
html,body { margin:0 auto; font:12px Arial,Helvetica,sans-serif,宋体; line-height:150%; TEXT-ALIGN:center; overflow-x:hidden; color:#000;}
body>table,body>div { margin-left:auto; margin-right:auto; clear:both;} /* M0Z */

全局微观定义

各容器和表单,主要控制文字、图片
table,div,tr,th,td,ul,li,img,form,h2,h3,h4 { font:12px Arial,Helvetica,sans-serif,宋体; margin:0; padding:0; border:0; color:#000;}
div,td,ul,li,h2,h3,h4 { LIST-STYLE-TYPE: none; word-break:break-all; Width:fixed; text-align:justify; text-justify:inter-ideograph; line-height:150%; border:0;}
input,select,textarea { color:#000; font:12px Arial,Helvetica,sans-serif,宋体;}

全局链接定义

触发出现下划线,链接颜色不变
a { font:12px Arial,Helvetica,sans-serif,宋体; color:#000; text-decoration: none;}
a:hover { text-decoration:underline;}

文字-标题

h2,h2 a { font-size:16px; font-weight:bold;}
h3,h3 a { font-size:14px; font-weight:bold;}
h4,h4 a { font-size:12px; font-weight:bold;}

文字-加粗与下划线

.f_b {}
.fs_b,.f_b * { font-weight:bold;}
.f_u {}
.fs_u,.f_u * { text-decoration:underline;}

文字-链接下划线效果

.a_vl a:link,.a_vl a:visited { text-decoration:underline;}
.a_vl a:hover{ text-decoration:none;} /* 触发无 */
.a_hl a:link,.a_hl a:visited { text-decoration:none;}
.a_hl a:hover{ text-decoration:underline;} /* 触发有 */
.a_nl a:link,.a_nl a:visited { text-decoration:none;}
.a_nl a:hover{ text-decoration:none;} /* 永久无 */

文字-大小

.f_s_10,.f_s_10 * { font-size:10px;}
.f_s_12,.f_s_12 * { font-size:12px;}
.f_s_14,.f_s_14 * { font-size:14px;}
.f_s_16,.f_s_16 * { font-size:16px;}

文字-颜色

.a_c_black,.a_c_black * { color:#000;}
.a_c_gray,.a_c_gray * { color:#666;}
.a_c_white,.a_c_white * { color:#fff;}
.a_c_red,.a_c_red * { color:#f00;}

图片-边框

.b_black {}
.bs_black,.b_black img { border:1px #000 solid;}
.b_gray {}
.bs_gray,.b_gray img { border:1px #999 solid;}
.b_white {}
.bs_white,.b_white img { border:1px #fff solid;}

图片-通栏广告

常用宽度通栏,包含纵向外补丁,兼容MOZ
.ban,.ban_white,.ban_black { width:760px;}
.ban img { margin:5px auto;}
.ban_white img { margin:5px auto; border:1px #fff solid;}
.ban_black img { margin:5px auto; border:1px #000 solid;}

列表-行高

.l_16,.l_16 * { line-height:16px;}
.l_18,.l_18 * { line-height:18px;}
.l_20,.l_20 * { line-height:20px;}
.l_22,.l_22 * { line-height:22px;}
.l_24,.l_24 * { line-height:24px;}
.l_26,.l_26 * { line-height:26px;}
.l_28,.l_28 * { line-height:28px;}
.l_30,.l_30 * { line-height:30px;}

列表-高度

.l_h_18,.l_h_18 * { height:18px;}
.l_h_20,.l_h_20 * { height:20px;}
.l_h_22,.l_h_22 * { height:22px;}

列表-单元格宽

.l_t_20 {}
.l_t_20 td { width:20%;}
.l_t_25 {}
.l_t_25 td { width:25%;}

列表-补丁
列表的横向内补丁


.l_p_5 {}
.l_p_5 * { padding-left: 5px;padding-right: 5px;}
.l_pr_5 {}
.l_pr_5 * { padding-right: 5px;}

浮动-位置,偏移,对齐
组合定义,控制位置左中右,控制左右浮动列表,单元格居顶,图片、表单的横向对齐


.t_l,.t_l * { text-align:left;}
.t_c,.t_c * { text-align:center;}
.t_r,.t_r *,.f_la,.f_lb,.f_ld,.f_ls { text-align:right;}
.f_l,.f_la a,.f_lb b,.f_ld div,.f_ls span { float:left;} /* f_la f_lb f_ld f_ls */
.f_r { float:right;}
.v_t { vertical-align:top;}
.v_m,.v_m_o,.v_m_o * { vertical-align:middle;}

间隔-内补丁
常用内补丁组合定义


.p_5 { padding: 5px;}
.p_t_5 { padding-top: 5px;}
.p_l_5 { padding-left: 5px;}
.p_r_5 { padding-right: 5px;}
.p_ape_5 { padding-top: 5px;padding-bottom: 5px;} /* apeak */
.p_lev_5 { padding-left: 5px;padding-right: 5px;} /* level */
.p_10 { padding: 10px;}
.p_t_10 { padding-top: 10px;}
.p_l_10 { padding-left: 10px;}
.p_r_10 { padding-right: 10px;}
.p_ape_10 { padding-top: 10px;padding-bottom: 10px;} /* apeak */
.p_lev_10 { padding-left: 10px;padding-right: 10px;} /* level */

间隔-外补丁
常用外补丁组合定义


.m_t_5 { margin:5px auto 0 auto;}
.m_a_5 { margin:5px auto;}

兼容
MOZ层自动延伸,清除浮动,MOZ居中


.h_h { height:0; clear:both; overflow:hidden; margin:0 auto;} /* M0Z */
.c_c { clear:both;}
.c_m,.c_l_m,.c_l_m div { margin:0 auto;} /* M0Z */

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: