Skip to content

Instantly share code, notes, and snippets.

@markyun
Last active September 25, 2022 14:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markyun/7672975 to your computer and use it in GitHub Desktop.
Save markyun/7672975 to your computer and use it in GitHub Desktop.
工作中常用的css样式
/*--------------------------------------------------------------
在CSS样式表中,合理有序的命名同样可以为整个CSS工作带来意想不到的简便。
为了更加符合搜索引擎的规范, 下面是一些常用的CSS代码命名标准。
页头: header (CSS中通常写为: #header)
登录条: loginBar
标志: logo
侧栏: sideBar
广告: banner
导航: nav
子导航: subNav
菜单: menu
子菜单: subMenu
搜索: search
滚动: scroll
页面主体:main
内容: content
标签页: tab
文章列表:list
提示信息:msg
小技巧:tips
栏目标题:title
加入: joinus
指南: guide
服务: service
热点: hot
新闻: news
下载: download
注册: regsiter
状态: status
按钮: btn
投票: vote
合作伙伴:partner
友情链接:friendLink
页脚: footer
版权: copyRight
CSS中 ID 的命名规范
外 套:  wrap
主导航:  mainNav
子导航:  subnav
页 脚:  footer
整个页面: content
页 眉:  header
页 脚:  footer
商 标:  label
标 题:  title
主导航:  mainNav(globalNav)
顶导航:  topnav
边导航:  sidebar
左导航:  leftsideBar
右导航:  rightsideBar
旗 志:  logo
标 语:  banner
菜单内容1: menu1Content
菜单容量: menuContainer
子菜单:  submenu
边导航图标:sidebarIcon
注释:   note
面包屑:  breadCrumb(即页面所处位置导航提示)
容器:   container
内容:   content
搜索:   search
登陆:   login
功能区:  shop(如购物车,收银台)
当前的   current
*/
/* CSS布局口诀 - CSS BUG顺口溜 */
/* · IE边框若显若无,须注意,定是高度设置已忘记; */
/* · 浮动产生有缘故,若要父层包含住,紧跟浮动要清除,容器自然显其中; */
/* · 三像素文本慢移不必慌,高度设置帮你忙; */
/* · 兼容各个浏览须注意,默认设置行高可能是杀手; */
/* · 独立清除浮动须铭记,行高设无,高设零,设计效果兼浏览; */
/* · 学布局须思路,路随布局原理自然直,轻松驾驭html,流水布局少hack,代码清爽,兼容好,友好引擎喜欢迎。 */
/* · 所有标签皆有源,只是默认各不同,span是无极,无极生两仪—内联和块级,img较特殊,但也遵法理,其他只是改造各不同,一个* 号全归原,层叠样式理须多练习,万物皆规律。 */
/* · 图片链接排版须小心,图片链接文字链接若对齐,padding和vertical-align:middle要设定,虽差微细倒无妨。 */
/* · IE浮动双边距,请用display:inline拘。 */
/* · 列表横向排版,列表代码须紧靠,空隙自消须铭记。 */
/*--------------------------------------------------------------
常用的CSS命名规则
头:header  内容:content/container  尾:footer  导航:nav  侧栏:sidebar
栏目:column  页面外围控制整体布局宽度:wrapper  左右中:left right center
登录条:loginbar  标志:logo  广告:banner  页面主体:main  热点:hot
新闻:news  下载:download  子导航:subnav  菜单:menu
子菜单:submenu  搜索:search  友情链接:friendlink  页脚:footer
版权:copyright  滚动:scroll  内容:content  标签页:tab
文章列表:list  提示信息:msg  小技巧:tips  栏目标题:title
加入:joinus  指南:guild  服务:service  注册:regsiter
状态:status  投票:vote  合作伙伴:partner
(1)页面结构
容器: container  页头:header  内容:content/container
页面主体:main  页尾:footer  导航:nav
侧栏:sidebar  栏目:column  页面外围控制整体布局宽度:wrapper
左右中:left right center
(2)导航
导航:nav  主导航:mainbav  子导航:subnav
顶导航:topnav  边导航:sidebar  左导航:leftsidebar
右导航:rightsidebar  菜单:menu  子菜单:submenu
标题: title  摘要: summary
(3)功能
标志:logo  广告:banner  登陆:login  登录条:loginbar
注册:regsiter  搜索:search  功能区:shop
标题:title  加入:joinus  状态:status  按钮:btn
滚动:scroll  标签页:tab  文章列表:list  提示信息:msg
当前的: current  小技巧:tips  图标: icon  注释:note
指南:guild 服务:service  热点:hot  新闻:news
下载:download  投票:vote  合作伙伴:partner
友情链接:link  版权:copyright
我们在使用脚本进行页面动态变换的时候,推荐的方法就是修改类名或者修改id名来修改显示样式,当然,常用的还是类名class。
修改类名-取名规范
(1)颜色:使用颜色的名称或者16进制代码,如
.red { color: red; }
.f60 { color: #f60; }
.ff8600 { color: #ff8600; }
(2)字体大小,直接使用’font+字体大小’作为名称,如
.font12px { font-size: 12px; }
.font9pt {font-size: 9pt; }
(3)对齐样式,使用对齐目标的英文名称,如
.left { float:left; }
.bottom { float:bottom; }
(4)标题栏样式,使用’类别+功能’的方式命名,如
.barnews { }
.barproduct { }
注意事项::
1.一律小写;
2.尽量用英文;
3.不加中杠和下划线;
4.尽量不缩写,除非一看就明白的单词.
常用css文件名
主要的 master.css  模块 module.css  基本共用 base.css
布局,版面 layout.css  主题 themes.css  专栏 columns.css
文字 font.css  表单 forms.css  补丁 mend.css  打印 print.css
*/
//按钮样式
a {
color: #08c;
font - size: 14px;
line - height: 33px;
background: #4899E0;
font - weight: bold;
color: #FFF;
padding: 4px 6px 4px;
margin - right: 12px;
}
//隐藏多余的文字
.question {
display: inline - block;
width: 300px;
height: 20px;
line - height: 20px;
text - overflow: ellipsis;
white - space: normal; * white - space: nowrap;
overflow: hidden;
}
@markyun
Copy link
Author

markyun commented Nov 29, 2013

CSS选择器的效率从高到低做了一个排序:

1.id选择器(#myid)2.类选择器(.myclassname)3.标签选择器(div,h1,p)4.相邻选择器(h1+p)5.子选择器(ul < li)6.后代选择器(li a)7.通配符选择器(*)8.属性选择器(a[rel="external"])9.伪类选择器(a:hover,li:nth-child)

上面九种选择器中ID选择器的效率是最高,而伪类选择器的效率则是最底。详细的介绍大家还可以点击Writing efficient CSS selectors。

/**
css按钮
*/

.btn:active { padding:4px 16px 2px; }

.btn{
background: -moz-linear-gradient(center top , #4884DA 0px, #096BF8 100%) repeat scroll 0 0 rgba(0, 0, 0, 0);
border: 1px solid blue;
border-radius: 2px;
box-shadow: 0 0 18px rgba(0, 0, 0, 0.25) inset;
color: #FFFFFF !important;
font-size: 13px;
font-weight: 700;
padding: 2px 16px;
text-align: center;
text-decoration: none !important;
text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.7);
width: 66px;
height: 27px;

@markyun
Copy link
Author

markyun commented Nov 29, 2013

/**
css3按钮
*/
.btn :before {
background-color: #EAEAEA;
border-radius: 140px;
bottom: -8px;
content: "";
left: -8px;
opacity: 0.5;
position: absolute;
right: -8px;
top: -8px;
z-index: -1;
}

.btn {
background-color: #EAEAEA;
background-image: -moz-linear-gradient(center top , #F6F6F6, #EAEAEA);
border-radius: 32px;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25), 0 2px 3px rgba(0, 0, 0, 0.1);
display: inline-block;
height: 64px;
line-height: 64px;
margin-right: 30px;
position: relative;
width: 64px;
}

@markyun
Copy link
Author

markyun commented Nov 29, 2013

/*
CSS伪元素实现的3D按钮
*/

.a_demo_five {
background-color:#3bb3e0;
width:150px;
display:inline-block;
font-family: 'Open Sans', sans-serif;
font-size:12px;
text-decoration:none;
color:#fff;
position:relative;
margin-top:40px;
padding-bottom:10px;
padding-top:10px;
background-image: linear-gradient(bottom, rgb(44,160,202) 0%, rgb(62,184,229) 100%);
background-image: -o-linear-gradient(bottom, rgb(44,160,202) 0%, rgb(62,184,229) 100%);
background-image: -moz-linear-gradient(bottom, rgb(44,160,202) 0%, rgb(62,184,229) 100%);
background-image: -webkit-linear-gradient(bottom, rgb(44,160,202) 0%, rgb(62,184,229) 100%);
background-image: -ms-linear-gradient(bottom, rgb(44,160,202) 0%, rgb(62,184,229) 100%);
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0, rgb(44,160,202)),
color-stop(1, rgb(62,184,229))
);
-webkit-border-bottom-right-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
-moz-border-radius-bottomright: 5px;
-moz-border-radius-bottomleft: 5px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px;
-webkit-box-shadow: inset 0px 1px 0px #2ab7ec, 0px 5px 0px 0px #156785, 0px 10px 5px #999;
-moz-box-shadow: inset 0px 1px 0px #2ab7ec, 0px 5px 0px 0px #156785, 0px 10px 5px #999;
-o-box-shadow: inset 0px 1px 0px #2ab7ec, 0px 5px 0px 0px #156785, 0px 10px 5px #999;
box-shadow: inset 0px 1px 0px #2ab7ec, 0px 5px 0px 0px #156785, 0px 10px 5px #999;
}

.a_demo_five:active {
top:0px;
background-image: linear-gradient(bottom, rgb(62,184,229) 0%, rgb(44,160,202) 100%);
background-image: -o-linear-gradient(bottom, rgb(62,184,229) 0%, rgb(44,160,202) 100%);
background-image: -moz-linear-gradient(bottom, rgb(62,184,229) 0%, rgb(44,160,202) 100%);
background-image: -webkit-linear-gradient(bottom, rgb(62,184,229) 0%, rgb(44,160,202) 100%);
background-image: -ms-linear-gradient(bottom, rgb(62,184,229) 0%, rgb(44,160,202) 100%);
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0, rgb(62,184,229)),
color-stop(1, rgb(44,160,202))
);
-webkit-box-shadow: inset 0px 4px 1px #0b698b, 0px 2px 0px 0px #156785, 0px 5px 3px #999;
-moz-box-shadow: 0px 2px 0px 1px #156785, 0px 5px 3px #999;
-o-box-shadow: 0px 2px 0px 1px #156785, 0px 5px 3px #999;
box-shadow: inset 0px 4px 1px #0b698b, 0px 2px 0px 0px #156785, 0px 5px 3px #999;
}
.a_demo_five::before {
background-color:#fff;
background-image:url(../images/heart.gif);
background-repeat:no-repeat;
background-position:center center;
content:"";
width:150px;
height:40px;
position:absolute;
top:-30px;
left:0px;
margin-top:-11px;
z-index:-1;
-webkit-border-top-left-radius: 5px;
-webkit-border-top-right-radius: 5px;
-moz-border-radius-topleft: 5px;
-moz-border-radius-topright: 5px;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
.a_demo_five:active::before {
top: -30px;
-webkit-box-shadow: 0px 3px 0px #ccc;
-moz-box-shadow: 0px 3px 0px #ccc;
-o-box-shadow: 0px 3px 0px #ccc;
box-shadow: 0px 3px 0px #ccc;
}

@markyun
Copy link
Author

markyun commented Nov 29, 2013

/*
CSS伪元素实现的3D按钮 2
*/
.a_demo_four {
background-color:#3bb3e0;
font-family: 'Open Sans', sans-serif;
font-size:12px;
text-decoration:none;
color:#fff;
position:relative;
padding:10px 20px;
padding-right:50px;
background-image: linear-gradient(bottom, rgb(44,160,202) 0%, rgb(62,184,229) 100%);
background-image: -o-linear-gradient(bottom, rgb(44,160,202) 0%, rgb(62,184,229) 100%);
background-image: -moz-linear-gradient(bottom, rgb(44,160,202) 0%, rgb(62,184,229) 100%);
background-image: -webkit-linear-gradient(bottom, rgb(44,160,202) 0%, rgb(62,184,229) 100%);
background-image: -ms-linear-gradient(bottom, rgb(44,160,202) 0%, rgb(62,184,229) 100%);
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0, rgb(44,160,202)),
color-stop(1, rgb(62,184,229))
);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-o-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: inset 0px 1px 0px #2ab7ec, 0px 5px 0px 0px #156785, 0px 10px 5px #999;
-moz-box-shadow: inset 0px 1px 0px #2ab7ec, 0px 5px 0px 0px #156785, 0px 10px 5px #999;
-o-box-shadow: inset 0px 1px 0px #2ab7ec, 0px 5px 0px 0px #156785, 0px 10px 5px #999;
box-shadow: inset 0px 1px 0px #2ab7ec, 0px 5px 0px 0px #156785, 0px 10px 5px #999;
}

.a_demo_four:active {
top:3px;
background-image: linear-gradient(bottom, rgb(62,184,229) 0%, rgb(44,160,202) 100%);
background-image: -o-linear-gradient(bottom, rgb(62,184,229) 0%, rgb(44,160,202) 100%);
background-image: -moz-linear-gradient(bottom, rgb(62,184,229) 0%, rgb(44,160,202) 100%);
background-image: -webkit-linear-gradient(bottom, rgb(62,184,229) 0%, rgb(44,160,202) 100%);
background-image: -ms-linear-gradient(bottom, rgb(62,184,229) 0%, rgb(44,160,202) 100%);
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0, rgb(62,184,229)),
color-stop(1, rgb(44,160,202))
);
-webkit-box-shadow: inset 0px 1px 0px #2ab7ec, 0px 2px 0px 0px #156785, 0px 5px 3px #999;
-moz-box-shadow: inset 0px 1px 0px #2ab7ec, 0px 2px 0px 0px #156785, 0px 5px 3px #999;
-o-box-shadow: inset 0px 1px 0px #2ab7ec, 0px 2px 0px 0px #156785, 0px 5px 3px #999;
box-shadow: inset 0px 1px 0px #2ab7ec, 0px 2px 0px 0px #156785, 0px 5px 3px #999;
}

.a_demo_four::before {
background-color:#2591b4;
background-image:url(../images/right_arrow.png);
background-repeat:no-repeat;
background-position:center center;
content:"";
width:20px;
height:20px;
position:absolute;
right:15px;
top:50%;
margin-top:-9px;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
-o-border-radius: 50%;
border-radius: 50%;
-webkit-box-shadow: inset 0px 1px 0px #052756, 0px 1px 0px #60c9f0;
-moz-box-shadow: inset 0px 1px 0px #052756, 0px 1px 0px #60c9f0;
-o-box-shadow: inset 0px 1px 0px #052756, 0px 1px 0px #60c9f0;
box-shadow: inset 0px 1px 0px #052756, 0px 1px 0px #60c9f0;
}

.a_demo_four:active::before {
top:50%;
margin-top:-12px;
-webkit-box-shadow: inset 0px 1px 0px #60c9f0, 0px 3px 0px #0e3871, 0px 6px 3px #1a80a6;
-moz-box-shadow: inset 0px 1px 0px #60c9f0, 0px 3px 0px #0e3871, 0px 6px 3px #1a80a6;
-o-box-shadow: inset 0px 1px 0px #60c9f0, 0px 3px 0px #0e3871, 0px 6px 3px #1a80a6;
box-shadow: inset 0px 1px 0px #60c9f0, 0px 3px 0px #0e3871, 0px 6px 3px #1a80a6;
}

@markyun
Copy link
Author

markyun commented Dec 2, 2013

/tips/

talkbubble {

   width: 120px;
   height: 80px;
   background: red;
   position: relative;
   -moz-border-radius:    10px;
   -webkit-border-radius: 10px;
   border-radius:         10px;
}

talkbubble:before {

   content:"";
   position: absolute;
   right: 100%;
   top: 26px;
   width: 0;
   height: 0;
   border-top: 13px solid transparent;
   border-right: 26px solid red;
   border-bottom: 13px solid transparent;
}

@markyun
Copy link
Author

markyun commented Dec 2, 2013

pacman {

width: 0px;
height: 0px;
border-right: 60px solid transparent;
border-top: 60px solid red;
border-left: 60px solid red;
border-bottom: 60px solid red;
border-top-left-radius: 60px;
border-top-right-radius: 60px;
border-bottom-left-radius: 60px;
border-bottom-right-radius: 60px;
}

@markyun
Copy link
Author

markyun commented Dec 4, 2013

position顾名思义就是定位。

他有以下这几种属性:static(默认),relative(相对定位),absolute(绝对定位)和fixed(固定定位)。

其中static和relative会占据文档流空间,他们并不是脱离文档的。

absolute和fixed是脱离文档流的,不会占据文档流空间。

不推荐用position来布局整个页面的大框架,而推荐用float或者文档流的默认方式。

@markyun
Copy link
Author

markyun commented Dec 4, 2013

HTML告诉我们一块内容是什么(或其意义),而不是它长的什么样子。

@markyun
Copy link
Author

markyun commented Dec 7, 2013

//清楚浮动
.c {
border: 0 none;
clear: both;
float: none !important;
font-size: 0;
height: 0 !important;
line-height: 0 !important;
margin: 0;
overflow: hidden;
padding: 0;
width: 0 !important;
}

@markyun
Copy link
Author

markyun commented Dec 7, 2013

高尽量用padding,慎用margin,height尽量补上100%,父级height有定值子级height不用100%,
子级全为浮动时底部补个空clear:both的div
宽尽量用margin,慎用padding,width算准实际要的减去padding

@markyun
Copy link
Author

markyun commented Dec 7, 2013

//背景透明问题

IE: filter: progid: DXImageTransform.Microsoft.Alpha(style=0,opacity=60);

IE: filter: alpha(opacity=10);

FF: opacity:0.6;

FF: -moz-opacity:0.10;

//最好两个都写,并将opacity属性放在下面

@markyun
Copy link
Author

markyun commented Dec 24, 2013

当你设置一个元素为 box-sizing: border-box; 时,此元素的内边距和边框不再会增加它的宽度。

  • {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment