css的一些使用技巧(含css3)
按钮渐变动画效果
- 改变渐变的位置
1
2
3
4
5
6
7
8
9button {
background-image: linear-gradient(#5187c4, #1c2f45);
background-size: auto 200%;
background-position: 0 100%;
transition: background-position 0.5s;
}
button:hover {
background-position: 0 0;
}
包裹长文本(不确定长度)
1 | pre { |
css设置模糊文本
1 | .blurry-text { |
用css实现省略号动画
1 | .loading:after { |
样式重置
1 | html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video { |
css清除浮动
1 | .clearfix:after { |
1 | .clearfix:before, .container:after { content: ""; display: table; } |
自定义文本选中后的颜色
1 | .txt::selection { |
css设置背景渐变
1 | .colorbox { |
css原图案
1 | body { |
flex-wrap
- 遇到问题自动换行木有效果
子元素需要设置具体的宽度1
2flex-wrap: wrap; // 父元素设置
flex: 1; // 子元素不能这样设置,必须是具体的宽度
emmet语法
- ul>li*3>{hello$}
css实现边框齿轮效果
- To Learn More…
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15<style>
.toothbg {
width: 100%;
height: 20px;
background: #ff94000;
background-image:-webkit-gradient(linear,50% 0,0 100%,from(transparent), color-stop(.5,transparent),color-stop(.5,#e5e5e5),to(#e5e5e5)),
-webkit-gradient(linear,50% 0,100% 100%,from(transparent), color-stop(.5,transparent),color-stop(.5,#e5e5e5),to(#e5e5e5));
background-image:-moz-linear-gradient(50% 0 -45deg,transparent,transparent 50%,#e5e5e5 50%,#e5e5e5),
-moz-linear-gradient(50% 0 -135deg,transparent,transparent 50%,#e5e5e5 50%,#e5e5e5);
background-size:30px 15px;
background-repeat:repeat-x;
background-position:0 100%;
}
</style>
<div class="toothbg"></div>
css实现动画效果
- 国外网站参考
- To Learn More…
css边框
1 | border-style: none | solid | dashed | dotted | double; |
css文本控制
first-letter 选中首个字符(针对块元素有作用)
1
2
3
4
5
6
7
8
9
10
11
12
13.txt {
margin: 100px auto;
width: 100px;
height: 100px;
border: 1px double #ff9400;
text-align: center;
}
.txt::first-letter {
font-size: 40px;
color: #ff0000;
}
<p class="txt">¥ 200</p>text-transform 指定文本大小写(应用在假设输入框只能输入大小写)
capitalize 首字母大写 | uppercase 全部大写 lowercase 全部小写 none
1
transform: capitalize | uppercase | lowercase | none;
word-spacing 指定空格间隙(前后空格没有用,设置的是字符之间空格)
1
word-spacing: 10px;
white-space 空白符处理
-
1
white-space: normal | nowrap | pre | pre-wrap | pre-line;
text-align: justify 设置两端对齐
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<style>
div {
outline: 1px solid;
}
span {
display: inline-block;
width: 100px;
line-height: 100px;
border-bottom: 1px solid lightcyan;
text-align: center;
background: cyan;
}
i {
display: inline-block;
width: 100px;
outline: 1px dashed;
}
</style>
<div>
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
<span>5</span>
<i></i><i></i><i></i>x
</div>