css常用效果总结
2017-12-04 16:48
225 查看
1、每逢大的灾难的时候,很多网站变成了灰色,如何让网站快速变灰?css代码是很简单的,用的是css的filter功能。
注:有一些网站FLASH动画的颜色不能被CSS滤镜控制,可以在FLASH代码的和之间插入:
2、DIV可编辑,就是让一个div变成一个类似input输入框的效果。
在div中添加contentEditable=”true” 属性就可以了,如下:
3、有些网站为了不让用户复制,设置了div禁止选择的功能,设置如下属性:
4、CSS 中form表单两端对齐
做form表单的时候,前面经常有姓名,年龄,公司名称等等,有的是2个字,有的是4个字,如何让字对齐呢?有的人的做法是打几个空格,但是这样不是很准确,最好的办法是如下:
5、input声音录入按钮,(仅支持谷歌)
如下图红色框框中的按钮:
6、给input的placeholder设置颜色
代码如下:
7、css3实现一个div设置多张背景图片及background-image属性
8、CSS选中状态修改
9、css input[type=file] 样式美化,input上传按钮美化
10、CSS :after 和:before选择器
11、透明度
12、超出长度显示省略号
单行文本显示…
多行文本显示…. (主要属性-webkit-line-clamp)
这个属性比较合适WebKit浏览器或移动端(绝大部分是WebKit内核的)浏览器。
跨浏览器兼容的方案
比较靠谱简单的做法就是设置相对定位的容器高度,用包含省略号(…)的元素模拟实现;
13、阴影效果
14、CSS强制换行和不换行
15、CSS 圆角
IE 9、Opera 10.5、Safari 5、Chrome 4和Firefox 4,都支持上述的border-radius属性。早期版本的Safari和Chrome,支持-webkit-border-radius属性,早期版本的Firefox支持-moz-border-radius属性。 目前来看,为了保证兼容性,只需同时设置-moz-border-radius和border-radius即可。
16、CSS3的一些前缀总结
css3为了更好的兼容多个浏览器,通常前面加一大堆前缀,有时候感觉很烦,前缀也容易忘记或者漏掉。下面总结一下!
-webkit 为Chrome/Safari
-moz 为Firefox
-ms 为IE
-o 为Opera
17、textarea禁止拖动
18.渐变效果
默认渐变是从上往下代码如下:
前面加一个参数,right,left,bottom,top等,就可以指定渐变方向:
html { filter: grayscale(100%);//IE浏览器 -webkit-filter: grayscale(100%);//谷歌浏览器 -moz-filter: grayscale(100%);//火狐 -ms-filter: grayscale(100%); -o-filter: grayscale(100%); filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); -webkit-filter: grayscale(1);//谷歌浏览器 }
注:有一些网站FLASH动画的颜色不能被CSS滤镜控制,可以在FLASH代码的和之间插入:
<param value="false" name="menu"/> <param value="opaque" name="wmode"/>
2、DIV可编辑,就是让一个div变成一个类似input输入框的效果。
在div中添加contentEditable=”true” 属性就可以了,如下:
<div id="div1" contentEditable="true" ></div> <div id="div2" contentEditable="true" ></div>
3、有些网站为了不让用户复制,设置了div禁止选择的功能,设置如下属性:
<div unselectable="on" onselectstart="return false;"> 你想复制我?门儿都没有!!! </div>
4、CSS 中form表单两端对齐
做form表单的时候,前面经常有姓名,年龄,公司名称等等,有的是2个字,有的是4个字,如何让字对齐呢?有的人的做法是打几个空格,但是这样不是很准确,最好的办法是如下:
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <style type="text/css"> td { text-align:justify; text-justify:distribute-all-lines;/*ie6-8*/ text-align-last:justify;/* ie9*/ -moz-text-align-last:justify;/*ff*/ -webkit-text-align-last:justify;/*chrome 20+*/ } @media screen and (-webkit-min-device-pixel-ratio:0){/* chrome*/ td:after{ content:"."; display: inline-block; width:100%; overflow:hidden; height:0; } } </style> </head> <body> <table border="1" cellspacing="1" cellpadding="10"> <tr> <td>姓名:</td> </tr> <tr> <td>工作单位:</td> </tr> <tr> <td>操作:</td> </tr> <tr> <td>所在地:</td> </tr> </table> </body> </html>
5、input声音录入按钮,(仅支持谷歌)
如下图红色框框中的按钮:
<!-- 添加 x-webkit-speech 属性就可以了。 --> <input type="text" class="box" name="s" id="s" class="inputText" placeholder="输入关键词" x-webkit-speech>
6、给input的placeholder设置颜色
代码如下:
::-webkit-input-placeholder { /* WebKit browsers */ color: #999; } :-moz-placeholder { /* Mozilla Firefox 4 to 18 */ color: #999; } ::-moz-placeholder { /* Mozilla Firefox 19+ */ color: #999; } :-ms-input-placeholder { /* Internet Explorer 10+ */ color: #999; }
7、css3实现一个div设置多张背景图片及background-image属性
div{ background:url("1.jpg") 0 0 no-repeat, url("2.jpg") 200px 0 no-repeat, url("3.jpg") 400px 201px no-repeat; } /* 也可以这么写 */ div{ background-image:url("1.jpg"),url("2.jpg"),url("3.jpg"); background-repeat: no-repeat, no-repeat, no-repeat; background-position: 0 0, 200px 0, 400px 201px; }
8、CSS选中状态修改
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <style type="text/css"> ::selection { background: yellowgreen; color: red; } </style> </head> <body> <p>我虽然是一个段落标签,但经常被人冷落。</p> </body> </html>
9、css input[type=file] 样式美化,input上传按钮美化
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <style type="text/css"> .file { position: relative; display: inline-block; background: #D0EEFF; border: 1px solid #99D3F5; border-radius: 4px; padding: 4px 12px; overflow: hidden; color: #1E88C7; text-decoration: none; text-indent: 0; line-height: 20px; } .file input { position: absolute; font-size: 100px; right: 0; top: 0; opacity: 0; } .file:hover { background: #AADFFD; border-color: #78C3F3; color: #004974; text-decoration: none; } </style> </head> <body> <a href="javascript:;" class="file">选择文件 <input type="file" name="" id=""> </a> </body> </html>
10、CSS :after 和:before选择器
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <style type="text/css"> .test-div{ position: relative; /*日常相对定位*/ width:150px; height:36px; border-radius:5px; border:black 1px solid; background: rgba(245,245,245,1) } .test-div:before{ content: ""; /*:before和:after必带技能,重要性为满5颗星*/ display: block; position: absolute; /*日常绝对定位*/ top:8px; width: 0; height: 0; border:6px solid transparent; left:-12px; border-right-color: #000; } </style> </head> <body> <div class="test-div"></div> </body> </html>
11、透明度
div{ opacity: .9; filter:alpha(opacity=90) } /* IE7和IE6中opacity是没有用的,在IE6中DIV透明的方法一般用filter; */ .div{ opacity: 0; cursor:pointer; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; filter: alpha(opacity=0); }
12、超出长度显示省略号
单行文本显示…
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <style type="text/css"> /* 一般要指定宽度,然后给如下四个属性。 */ span{ width:200px; display:block; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; } </style> </head> <body> <span>我是单行文字省略我是单行文字省略</span> </body> </html>
多行文本显示…. (主要属性-webkit-line-clamp)
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <style type="text/css"> /* 一般要指定宽度,然后给如下四个属性。 */ p { width: 200px; overflow : hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; } </style> </head> <body> <p>我是多行文字省略我是多行文字省略我是多行文字省略行文字省略行文字省略行文字省略</p> </body> </html>
这个属性比较合适WebKit浏览器或移动端(绝大部分是WebKit内核的)浏览器。
跨浏览器兼容的方案
比较靠谱简单的做法就是设置相对定位的容器高度,用包含省略号(…)的元素模拟实现;
p { position:relative; line-height:1.4em; /* 3 times the line-height to show 3 lines */ height:4.2em; overflow:hidden; } p::after { content:"..."; font-weight:bold; position:absolute; bottom:0; right:0; padding:0 20px 1px 45px; // background:url(和网页背景颜色一样的一张背景图) repeat-y; background-color:#fff; } /* 注意: height高度正好是line-height的3倍; 结束的省略好用了半透明的png做了减淡的效果,或者设置背景颜色; IE6-7不显示content内容,所以要兼容IE6-7可以是在内容中加入一个标签,比如用...去模拟; 要支持IE8,需要将::after替换成:after; */
13、阴影效果
/* 盒子阴影 */ box-shadow: 2px 2px 10px 4px #333333; /* 文子阴影 */ text-shadow: 1px 1px 0px #fff;
14、CSS强制换行和不换行
/* 自动换行 */ div{ word-wrap: break-word; word-break: normal; } /* 强制英文单词断行 */ div{ word-break:break-all; } /* 强制不换行 */ div{ white-space:nowrap; }
15、CSS 圆角
IE 9、Opera 10.5、Safari 5、Chrome 4和Firefox 4,都支持上述的border-radius属性。早期版本的Safari和Chrome,支持-webkit-border-radius属性,早期版本的Firefox支持-moz-border-radius属性。 目前来看,为了保证兼容性,只需同时设置-moz-border-radius和border-radius即可。
-moz-border-radius: 15px; border-radius: 15px; /* (注意:border-radius必须放在最后声明,否则可能会失效。) */ /* 另外,早期版本Firefox的单个圆角的语句,与标准语法略有不同。 */ -moz-border-radius-topleft(标准语法:border-top-left-radius) -moz-border-radius-topright(标准语法:border-top-right-radius) -moz-border-radius-bottomleft(标准语法:border-bottom-left-radius) -moz-border-radius-bottomright(标准语法:border-bottom-right-radius)
16、CSS3的一些前缀总结
css3为了更好的兼容多个浏览器,通常前面加一大堆前缀,有时候感觉很烦,前缀也容易忘记或者漏掉。下面总结一下!
-webkit 为Chrome/Safari
-moz 为Firefox
-ms 为IE
-o 为Opera
17、textarea禁止拖动
resize: none; //禁止拖动 /* 以下是resize属性的的各个取值: none:用户不能操纵机制调节元素的尺寸; both:用户可以调节元素的宽度和高度; horizontal:用户可以调节元素的宽度; vertical:让用户可以调节元素的高度; inherit:默认继承。 */
18.渐变效果
默认渐变是从上往下代码如下:
background:#ed4a60; background: -webkit-linear-gradient(#ed5a5e, #ed3a61); background: -o-linear-gradient(#ed5a5e, #ed3a61); background: -moz-linear-gradient(#ed5a5e, #ed3a61); background: linear-gradient(#ed5a5e, #ed3a61);
前面加一个参数,right,left,bottom,top等,就可以指定渐变方向:
background:-moz-linear-gradient(left,#ace,#f96);/*Mozilla*/ background:-webkit-gradient(linear,0 50%,100% 50%,from(#ace),to(#f96));/*Old gradient for webkit*/ background:-webkit-linear-gradient(left,#ace,#f96);/*new gradient for Webkit*/ background:-o-linear-gradient(left,#ace,#f96); /*Opera11*/
相关文章推荐
- 常用的CSS效果总结
- css常用效果总结
- css常用效果总结
- Css常用效果总结 — 快速查询笔记
- Css常用效果总结
- css常用效果总结
- 前端笔试面试中的常用知识点总结(CSS)
- CSS常用规则总结
- 常用CSS缩写语法总结
- 初识CSS--常用元素总结(五)-表格和列表
- 常用CSS缩写语法总结
- 常用CSS缩写语法总结
- CSS一些常用属性总结
- css常用浮出层(tip效果)的写法
- 常用CSS缩写语法总结
- css常用属性总结-盒子模型
- iOS应用中UILabel文字显示效果的常用设置总结
- [置顶] 常用CSS优化总结——网络性能与语法性能建议
- cocos2d的常用动作及效果总结之四:Special Actions
- CSS一些常用的总结