♌

Mr. Leo


  • 首页

  • 分类26

  • 标签142

  • 归档138

  • 关于

  • 搜索

Apache

发表于 2017-01-07 | 更新于 2021-05-12 | 分类于 工具 | 评论数: 0 | 阅读次数:

下载

  1. 登录https://httpd.apache.org/download.cgi 这个地址
  2. 进入如下界面后,选择第一项ApacheHaus,这是个第三方下载平台,在它的网站下载独立的 Apache 会是一个压缩包,第二项也是独立的 Apache 下载地址,另外三个是集成开发环境。
  3. 在下载界面中,会发现 VC9 和 VC11 字样,通过阅读相关内容得知:
    • VC9 是指用 VS2008 编译的
    • VC11 是指用 VS2012 编译的,VC11 无法在 windows xp 和 server 2003 中使用

配置

  • 进入解压后的 Apache 目录,找到 ~\Apache\conf\httpd.conf 文件并用编辑器打开
  • 找到 Define SRVROOT ,将后面的地址改成本地 Apache 安装存放的地址,例如:

    1
    Define SRVROOT "c:/PortableSoft/Apache"
  • 找到 Listene 80 ,若 80 端口被占用(可在 cmd 下用命令 netstat -a 查看),则将 80 端口改为别的

  • 找到 DocumentRoot,将后面的地址修改为需要的 wwwroot
  • 找到 DirectoryIndex,将后面的文件修改为需要的默认启动页面

安装主服务

  • 管理员打开 CMD 窗口,输入:

    1
    "c:\PortableSoft\Apache\bin\httpd.exe" -k install -n apache

    带有引号的。
    该命令的意思是,安装 apache 服务,并将该服务名称命名为 apache(也可以改成别的)

  • Win+R 运行输入 services.msc,找到刚刚安装的 apache 服务,右键属性中将启动类型设置为手动
  • 进入 Apache 安装目录,找到c:\PortableSoft\Apache\bin\ApacheMonitor.exe,运行后在系统右下角状态栏中打开窗口界面点击Start启动服务

卸载

  1. 停止 Apache 服务
  2. 管理员打开 CMD 窗口,输入:
    1
    sc delete apache

参考

  • Apache 修改端口 默认路径配置修改方法

console

发表于 2017-01-07 | 更新于 2021-05-12 | 分类于 前端 , javascript | 评论数: 0 | 阅读次数:

https://www.cnblogs.com/Wayou/p/chrome-console-tips-and-tricks.html

显示信息的命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE html>
<html>
<head>
<title>常用console命令</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script type="text/javascript">
console.log('hello');
console.info('信息');
console.error('错误');
console.warn('警告');
</script>
</body>
</html>

最常用的就是console.log了。

占位符

console上述的集中度支持printf的占位符格式,支持的占位符有:字符(%s)、整数(%d或%i)、浮点数(%f)和对象(%o)。

1
2
3
<script type="text/javascript">
console.log("%d年%d月%d日",2011,3,26);
</script>

信息分组

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!DOCTYPE html>
<html>
<head>
<title>常用console命令</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script type="text/javascript">

console.group("第一组信息");
    console.log("第一组第一条:我的博客(https://www.ido321.com)");
    console.log("第一组第二条:CSDN(https://blog.csdn.net/u011043843)");
  console.groupEnd();

   console.group("第二组信息");
    console.log("第二组第一条:程序爱好者QQ群: 259280570");
    console.log("第二组第二条:欢迎你加入");
   console.groupEnd();

</script>
</body>
</html>

查看对象的信息

console.dir()可以显示一个对象所有的属性和方法。

1
2
3
4
5
6
7
8
<script type="text/javascript">
var info = {
blog:"https://www.ido321.com",
QQGroup:259280570,
message:"程序爱好者欢迎你的加入"
};
console.dir(info);
</script>

显示某个节点的内容

console.dirxml()用来显示网页的某个节点(node)所包含的html/xml代码。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html>
<head>
<title>常用console命令</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div id="info">
<h3>我的博客:www.ido321.com</h3>
<p>程序爱好者:259280570,欢迎你的加入</p>
</div>
<script type="text/javascript">
var info = document.getElementById('info');
console.dirxml(info);
</script>
</body>
</html>

判断变量是否是真

console.assert()用来判断一个表达式或变量是否为真。如果结果为否,则在控制台输出一条相应信息,并且抛出一个异常。

1
2
3
4
5
6
<script type="text/javascript">
  var result = 1;
  console.assert( result );
  var year = 2014;
  console.assert(year == 2018 );
</script>

1是非0值,是真;而第二个判断是假,在控制台显示错误信息

追踪函数的调用轨迹

console.trace()用来追踪函数的调用轨迹。

1
2
3
4
5
6
7
8
9
10
11
<script type="text/javascript">
/*函数是如何被调用的,在其中加入console.trace()方法就可以了*/
  function add(a,b){
console.trace();
    return a+b;
  }
  var x = add3(1,1);
  function add3(a,b){return add2(a,b);}
  function add2(a,b){return add1(a,b);}
 function add1(a,b){return add(a,b);}
</script>

计时功能

console.time()和console.timeEnd(),用来显示代码的运行时间。

1
2
3
4
5
6
7
<script type="text/javascript">
  console.time("控制台计时器一");
  for(var i=0;i<1000;i++){
    for(var j=0;j<1000;j++){}
  }
  console.timeEnd("控制台计时器一");
</script>

运行时间是38.84ms

console.profile()的性能分析

性能分析(Profiler)就是分析程序各个部分的运行时间,找出瓶颈所在,使用的方法是console.profile()。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<script type="text/javascript">
function All() {
alert(11);
for (var i = 0; i < 10; i++) {
funcA(1000);
}
funcB(10000);
}

function funcA(count) {
for (var i = 0; i < count; i++) {}
}

function funcB(count) {
for (var i = 0; i < count; i++) {}
}
console.profile('性能分析器');
All();
console.profileEnd();
</script>

css 代码片段

发表于 2017-01-07 | 更新于 2021-05-12 | 分类于 前端 , css | 评论数: 0 | 阅读次数:

以下是常用的代码收集,没有任何技术含量,只是填坑的积累。转载请注明出处,谢谢。

1. css 2.x

  • 文字换行

    1
    2
    3
    4
    5
    6
    7
    /*强制不换行*/
    white-space:nowrap;
    /*自动换行*/
    word-wrap: break-word;
    word-break: normal;
    /*强制英文单词断行*/
    word-break:break-all;
  • 两端对齐

    1
    text-align:justify;text-justify:inter-ideogra
  • 去掉Webkit(chrome)浏览器中input(文本框)或textarea的黄色焦点框

    1
    2
    input,button,select,textarea{ outline:none;}
    textarea{ font-size:13px; resize:none;}
  • 去掉chrome记住密码后自动填充表单的黄色背景

  • ie6: position:fixed

1
2
3
.fixed-top /* position fixed Top */{position:fixed;bottom:auto;top:0; }
* html .fixed-top /* IE6 position fixed Top */{position:absolute;bottom:auto;top:expression(eval(document.documentElement.scrollTop));}
*html{background-image:url(about:blank);background-attachment:fixed;}
  • clearfix
1
2
3
4
5
6
7
8
9
.clearfix:after{visibility:hidden;display:block;font-size:0;content:" ";clear:both;height:0;}
.clearfix{display:inline-block;}
html[xmlns] .clearfix{display:block;}
* html .clearfix{height:1%;}

.clearfix{*zoom: 1;}
.clearfix:after{clear:both;display:table;content:"";}

.clearfix{overflow:hidden;_zoom:1;}

https://www.cnblogs.com/blog-leo/p/3959217.html
https://www.daqianduan.com/3606.html

  • seperate-table
1
2
3
4
.tab{border-collapse:separate;border:1px solid #e0e0e0;}
.tab th,.tab td{padding:3px;font-size:12px;background:#f5f9fb;border:1px solid;border-color:#fff #deedf6 #deedf6 #fff;}
.tab th{background:#edf4f0;}
.tab tr.even td{background:#fff;}
1
2
3
4
5
6
7
8
9
10
<table class="tab" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<th>111</th>
<td>222</td>
</tr>
<tr>
<th>111</th>
<td>222</td>
</tr>
</table>
  • min-height: 最小高度兼容代码
1
.minheight500{min-height:500px;height:auto !important;height:500px;overflow:visible;}
  • 鼠标不允许点击
1
cursor:not-allowed;
  • mac font: osx平台字体优化
1
font-family:"Hiragino Sans GB","Hiragino Sans GB W3",'微软雅黑';
  • 文字过多后显示省略号
1
.ellipsis,.ell{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

2. css 3

  • 投影
1
2
3
4
.b{box-shadow:inset 1px -1px 0 #f1f1f1;text-shadow:1px 1px 0px #630;}
filter:progid:DXImageTransform.Microsoft.gradient(enabled='true',startColorstr='#99000000',endColorstr='#99000000');background:rgba(0,0,0,.6);

background:rgba(0,0,0,0.5);filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#50000000',endColorstr='#50000000')\9;
  • search占位
1
2
3
4
5
6
7
8
9
::-webkit-input-placeholder {}
::-moz-input-placeholder {}
input:focus::-webkit-input-placeholder { color: transparent; }
-webkit-appearance:none; google边框去除
input[type="search"]{-webkit-appearance:textfield;} // 去除chrome默认样式
https://i.wanz.im/2011/02/04/remove_border_from_input_type_search/
https://blog.csdn.net/do_it__/article/details/6789699
line-height: normal; /* for non-ie */
line-height: 22px\9; /* for ie */
  • title 换行
1
&#13;
  • 关闭 x 符号
1
&#215;
  • 全部浏览器的兼容代码生成
    CSS 实现 textArea 的 placeholder 换行

  • 阻止默认事件

1
pointer-events:none;
  • 变灰 gray
1
2
3
4
5
6
7
8
9
10
html{
filter: grayscale(100%);
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
filter: url("data:image/svg+xml;utf8,<svg xmlns=\'https://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale");
filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
-webkit-filter: grayscale(1);
}
  • firefox 阻止选中
1
-moz-user-focus:ignore;-moz-user-input:disabled;-moz-user-select:none;
  • 箭头
1
2
3
4
display:block;border:solid transparent;line-height: 0;width:0; height:0;border-top:solid #0288ce;border-width:8px 6px 0 6px;

border-style:solid; border-width:7px; border-color:transparent transparent transparent #ff7020;
position:absolute;top: 0;left: 0;border-width:20px;border-style:solid;border-color:#d1ddde transparent transparent #d1ddde;

ie6 bug测试,把border-style设为dashed.

  • 取消textarea右下角可拖动手柄
1
resize:none
  • 取消chrome form表单的聚焦边框

    1
    2
    input,button,select,textarea{outline:none}
    textarea{resize:none}
  • 取消a链接的黄色边框

    1
    a{-webkit-tap-highlight-color:rgba(0,0,0,0);}
  • webkit 水平居中

1
display:-webkit-box;-webkit-box-pack:center; -webkit-box-align: center;
  • 取消chrome 搜索x提示
1
2
3
4
5
6
input[type=search]::-webkit-search-decoration,
input[type=search]::-webkit-search-cancel-button,
input[type=search]::-webkit-search-results-button,
input[type=search]::-webkit-search-results-decoration {
display: none;
}
  • chrome取消默认黄色背景
1
2
3
4
5
6
7
input:-webkit-autofill {-webkit-box-shadow: 0 0 0px 1000px white inset;}
input:-webkit-autofill,
textarea:-webkit-autofill,
select:-webkit-autofill {
-webkit-box-shadow: 0 0 0 1000px white inset;
}
autocomplete="off"
  • 手机版本网页a标记虚线框问题
1
a:focus {outline:none;-moz-outline:none;}
  • 焦点去除背景
1
2
-webkit-tap-highlight-color:rgba(255, 255, 255, 0);
-webkit-tap-highlight-color:transparent; // i.e. Nexus5/Chrome and Kindle Fire HD 7''
  • placeholder占位符颜色自定义
1
2
input:-moz-placeholder {color: #369;}
::-webkit-input-placeholder {color:#369;}
  • IOS 禁用高亮
1
-webkit-tap-highlight-color:rgba(255,0,0,0.5);-webkit-tap-highlight-color:transparent; /* For some Androids */
  • 用户不能选择元素中的任何内容
1
user-select:none
  • 移动端H5点击阴影
1
2
3
4
5
6
div,a,img {
-webkit-tap-highlight-color: transparent;
-webkit-touch-callout: none;
-webkit-user-select: none;
user-select:none;
}
  • IOS iframe 滚动 滚动回弹特效
1
-webkit-overflow-scrolling:touch;overflow-y:scroll;
  • 禁止选中文本
1
2
3
4
-moz-user-select:none;
-webkit-user-select:none;
-ms-user-select:none;
user-select:none;
  • 模糊(毛玻璃)效果1
  • 模糊(毛玻璃)效果2
  • 模糊(毛玻璃)逼真效果
1
2
3
4
5
6
.blur {    
-webkit-filter: blur(10px); /* Chrome, Opera */
-moz-filter: blur(10px);
-ms-filter: blur(10px);
filter: blur(10px);
}
1
2
<img src="mm1.jpg" />
<img src="mm1.jpg" class="blur" />
  • 显示旋转加载图片,下拉加载数据
1
2
3
4
5
6
7
8
9
#pullDown .pullDownIcon{display:inline-block;vertical-align:middle;width:40px;height:40px;background:url(https://github.com/chalecao/chale/blob/master/pull-icon%402x.png) 0 0 no-repeat;-webkit-background-size:40px 80px;background-size:40px 80px;-webkit-transition-property:-webkit-transform;-webkit-transition-duration:250ms}
#pullDown .pullDownIcon{-webkit-transform:rotate(0deg) translateZ(0)}
#pullDown .pullDownLabel{display:inline-block;vertical-align:middle;margin-left:5px;}
#pullDown.flip .pullDownIcon{-webkit-transform:rotate(-180deg) translateZ(0)}
#pullDown.loading .pullDownIcon{background-position:0 100%;-webkit-transform:rotate(0deg) translateZ(0);-webkit-transition-duration:0ms;-webkit-animation-name:loading;-webkit-animation-duration:2s;-webkit-animation-iteration-count:infinite;-webkit-animation-timing-function:linear}
@-webkit-keyframes loading{
from{-webkit-transform:rotate(0deg) translateZ(0)}
to{-webkit-transform:rotate(360deg) translateZ(0)}
}
1
2
3
<div id="pullDown" class="none loading">
<span class="pullDownIcon"></span><span class="pullDownLabel">正在载入中...</span>
</div>
  • 居中
  • css media :通过媒体查询为不同的设备和大小配置不同的样式。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* media */
/* 横屏 */
@media screen and (orientation:landscape){

}
/* 竖屏 */
@media screen and (orientation:portrait){

}
/* 窗口宽度<960,设计宽度=768 */
@media screen and (max-width:959px){

}
/* 窗口宽度<768,设计宽度=640 */
@media screen and (max-width:767px){

}
/* 窗口宽度<640,设计宽度=480 */
@media screen and (max-width:639px){

}
/* 窗口宽度<480,设计宽度=320 */
@media screen and (max-width:479px){

}
/* windows UI 贴靠 */
@media screen and (-ms-view-state:snapped){

}
/* 打印 */
@media print{

}
  • flexbox
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
.flex-cont{
/*定义为flexbox的“父元素”*/
display: -webkit-box;
display: -webkit-flex;
display: flex;
/*子元素沿主轴对齐方式居中*/
-webkit-box-pack: center;
-webkit-justify-content: center;
justify-content: center;
/*子元素沿侧轴对齐方式垂直居中*/
-webkit-box-align: center;
-webkit-align-items: center;
align-items: center;
/*指定主轴的伸缩流方向是纵向的*/
-webkit-box-orient:vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
flex-direction: column;
}
.flex-item{
/*不要给flexbox里的子元素设置“margin:auto”的属性,在部分安卓机下,它会导致该元素的宽度撑开到100%占位*/
/*在旧版的规范中,使用比例伸缩布局时,子元素的内容长短不同会导致无法“等分”,这个时候,我们需要给子元素设置一个“width:0%”来解决问题*/
width: 0%;
/*给“子元素”赋予自由伸缩的能力*/
-webkit-box-flex: 1;
-webkit-flex: 1;
flex:1;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*使用无衬线字体*/
body {
font-family: "Helvetica Neue", Helvetica, STHeiTi, sans-serif;
}

/*禁止长按链接与图片弹出菜单*/
a, img {
-webkit-touch-callout: none;
}

/*禁止选中文本*/
html, body {
-webkit-user-select: none;
user-select: none;
}

/* 如何禁止选中文字 */
.noselect {
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Chrome/Safari/Opera */
-khtml-user-select: none; /* Konqueror */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently not supported by any browser */
}

/*去掉webkit默认的表单样式*/
button,input,optgroup,select,textarea {
-webkit-appearance:none;
}

/*去掉a、input和button点击时的蓝色外边框和灰色半透明背景*/
a,button,input,optgroup,select,textarea {
-webkit-tap-highlight-color:rgba(0,0,0,0);
}

/*修改webkit中input的planceholder样式*/
input::-webkit-input-placeholder {
color:#ccc;
}

/*修改webkit中focus状态下input的planceholder样式*/
input:focus::-webkit-input-placeholder {
color:#f00;
}

/*禁止IOS调整字体大小*/
body {
-webkit-text-size-adjust: 100%!important;
}

/*隐藏Android的语音输入按钮*/
input::-webkit-input-speech-button {
display: none;
}

版本规范

发表于 2017-01-07 | 更新于 2021-05-12 | 分类于 规范 | 评论数: 0 | 阅读次数:

版本号由 x.y.z 三位组成,符合 语义化版本号 规范:

  • 主版本号:当做了不兼容的 API 修改
  • 次版本号:当做了向下兼容的功能性新增
  • 修订号:当做了向下兼容的问题修正
阅读全文 »

C#开发规范

发表于 2017-01-07 | 更新于 2021-05-12 | 分类于 规范 | 评论数: 0 | 阅读次数:

注释

  • 类头 注释
1
2
3
4
5
6
7
8
9
10
11
12
/*****************************************************************
* ADD:-----------------------------------------------------------
* VER:1.0
* DTE:2015-4-21 10:39:36
* ATU:作者
* DES:说明
* MOD:-----------------------------------------------------------
* VER:1.1
* DTE:2015-4-21 10:39:36
* ATU:作者
* DES:说明
*****************************************************************/
  • 方法 注释
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//#region 获取xxx分页数据
/// <summary>
/// 获取xxx分页数据
/// </summary>
/// <param name="page">页码</param>
/// <returns>返回分页列表</returns>
public void GetPageList(int page){
//TODO:未完成
...

//#region 代码块 - 逻辑操作
...
//#endregion
}
//#endregion
  • Enumerate / Model 注释
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public void BooleanStates{
/// <summary>
/// output true value only
/// </summary>
True,

/// <summary>
/// output false value only
/// </summary>
False,

/// <summary>
/// output true and false value both
/// </summary>
TrueFalse
}

MVC - C#框架规范

-
-
-

javascript规范

发表于 2017-01-07 | 更新于 2021-05-12 | 分类于 规范 | 评论数: 0 | 阅读次数:

javascript 注释

HBuilder 官方文档

阅读全文 »

CSS文件结构规范

发表于 2017-01-07 | 更新于 2021-05-12 | 分类于 规范 | 评论数: 0 | 阅读次数:

Sass 文件夹结构说明

参考:https://sass-guidelin.es/zh/#section-53

下载 Sass 文件结构示例

Base 文件夹

base/文件夹存放项目中的模板文件。在这里,可以找到重置文件、排版规范文件或者一个样式表——定义一些 HTML 元素公认的标准样式(我喜欢命名为_base.scss)。

  • _base.scss:公认的标准样式
  • _reset.scss:浏览器重置样式
  • _animations.scss:动画
  • 。。。

Layout / Partials 文件夹

layout/(partials/) 文件夹存放构建网站或者应用程序使用到的布局部分。该文件夹存放网站主体(头部、尾部、导航栏、侧边栏…)的样式表、栅格系统甚至是所有表单的 CSS 样式。

Components / Modules 文件夹

对于小型组件来说,有一个 components/ 文件夹来存放。相对于 layout/ 的宏观(定义全局线框结构),components/ 更专注于局部组件。该文件夹包含各类具体模块,基本上是所有的独立模块,比如一个滑块、一个加载块、一个部件……由于整个网站或应用程序主要由微型模块构成,components/ 中往往有大量文件。

Pages 文件夹

如果页面有特定的样式,最好将该样式文件放进 pages/ 文件夹并用页面名字。例如,主页通常具有独特的样式,因此可以在 pages/ 下包含一个 _home.scss 以实现需求。
取决于各自的开发流程,这些文件可以使用你自己的前缀命名,避免在最终样式表中与他人的样式表发生合并。一切完全取决于你。

Themes 文件夹

在大型网站和应用程序中,往往有多种主题。虽有多种方式管理这些主题,但是我个人更喜欢把它们存放在 themes/ 文件夹中。

Utils / Helpers / Utilities 文件夹

utils/ 文件夹包含了整个项目中使用到的 Sass 辅助工具,这里存放着每一个全局变量、函数、混合宏和占位符。
该文件夹的经验法则是,编译后这里不应该输出任何 CSS,单纯的只是一些 Sass 辅助工具。
当项目体量庞大工具复杂时,通过主题而不是类型分类整理可能更有帮助,比如排版(_typography.scss)、主题(_theming.scss)等。每一个文件都包含所有的相关信息:变量、函数、混合宏和占位符。这样做可以让维护更加单,特别针对于文件较长的情况。

Vendors 文件夹

最后但并非最终的是,大多数的项目都有一个 vendors/ 文件夹,用来存放所有外部库和框架(Normalize, Bootstrap, jQueryUI, FancyCarouselSliderjQueryPowered……)的 CSS 文件。将这些文件放在同一个文件中是一个很好的说明方式:”嘿,这些不是我的代码,无关我的责任。”
如果你重写了任何库或框架的部分,建议设置第 8 个文件夹 vendors-extensions/ 来存放,并使用相同的名字命名。
例如,vendors-extensions/_boostrap.scss 文件存放所有重写 Bootstrap 默认 CSS 之后的 CSS 规则。这是为了避免在原库或者框架文件中进行二次编辑——显然不是好方法。

入口文件

主文件(通常写作 main.scss)应该是整个代码库中唯一开头不用下划线命名的 Sass 文件。除 @import 和注释外,该文件不应该包含任何其他代码。


文件引入方式:

为了保持可读性,主文件应遵守如下两种准则一种

方式一:

  • 每个 @import 引用一个文件;
  • 每个 @import 单独一行;
  • 从相同文件夹中引入的文件之间不用空行;
  • 从不同文件夹中引入的文件之间用空行分隔;
  • 忽略文件扩展名和下划线前缀。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
@import 'utils/variables';
@import 'utils/functions';
@import 'utils/mixins';
@import 'utils/placeholders';

@import 'vendors/bootstrap';
@import 'vendors/jquery-ui';
@import 'vendors-extensions/bootstrap';
@import 'vendors-extensions/jquery-ui';

@import 'base/reset';
@import 'base/typography';

@import 'layout/navigation';
@import 'layout/grid';
@import 'layout/header';
@import 'layout/footer';
@import 'layout/sidebar';
@import 'layout/forms';

@import 'components/buttons';
@import 'components/carousel';
@import 'components/cover';
@import 'components/dropdown';

@import 'pages/home';
@import 'pages/contact';

@import 'themes/theme';
@import 'themes/admin';

方式二:

  • 每个文件夹只使用一个@import
  • 每个@import 之后都断行
  • 每个文件占一行
  • 新的文件跟在最后的文件夹后面
  • 文件扩展名都可以省略
1
2
3
4
5
6
7
8
9
10
11
12
13
@import 'utils/variables', 'utils/functions', 'utils/mixins', 'utils/placeholders';

@import 'vendors/bootstrap', 'vendors/jquery-ui', 'vendors-extensions/bootstrap', 'vendors-extensions/jquery-ui';

@import 'base/reset', 'base/typography';

@import 'layout/navigation', 'layout/grid', 'layout/header', 'layout/footer', 'layout/sidebar', 'layout/forms';

@import 'components/buttons', 'components/carousel', 'components/cover', 'components/dropdown';

@import 'pages/home', 'pages/demo';

@import 'themes/theme', 'themes/admin';

另一个有意思的方面,由业内已流行的 Harry Roberts, Dave Rupert 和 Chris Coyier 引起的,那就是将所有的 CSS 声明、Hack 行为和我们不支持的行为放入一个 shame file。该文件命名为 _shame.scss,在所有文件之后被引用,放在所有样式表的最后。

1
2
3
4
5
6
7
8
9
10
/**
* Nav specificity fix.
*
* Someone used an ID in the header code (`#header a {}`) which trumps the
* nav selectors (`.site-nav a {}`). Use !important to override it until I
* have time to refactor the header stuff.
*/
.site-nav a {
color: #bada55 !important;
}

CSS选择器嵌套规范

发表于 2017-01-07 | 更新于 2021-05-12 | 分类于 规范 | 评论数: 0 | 阅读次数:

应该尽可能避免选择器嵌套。

例外

在最外层选择器中嵌套伪类和伪元素是被允许,也是受推荐的。

1
2
3
4
5
6
7
8
9
10
11
.foo {
color: red;

&:hover {
color: green;
}

&::before {
content: 'pseudo-element';
}
}

使用选择器嵌套选择伪类和伪元素不仅仅有道理的(因为它的处理功能与选择器紧密相关),而且有助于保持总体的一致性。
当然,如果使用类似 .is-active 类名来控制当前选择器状态,也可以这样使用选择器嵌套。

1
2
3
4
5
6
7
.foo {
// ...

&.is-active {
font-weight: bold;
}
}

这并不是最重要的,当一个元素的样式在另一个容器中有其他指定的样式时,可以使用嵌套选择器让他们保持在同一个地方。

1
2
3
4
5
6
7
.foo {
// ...

.no-opacity & {
display: none;
}
}
1…141516…18
Leo

Leo

😆
138 日志
26 分类
142 标签
RSS
QQ 微博 E-Mail GitHub 我的主页
Creative Commons
友情链接
  • ZM
  • july
0%
© 2016 – 2021 Leo
由 Hexo 强力驱动 v3.9.0
|
主题 – NexT.Gemini v7.0.1
|