1.黑白图像
img.desaturate {
filter: grayscale(100%);
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
}
2. 使用 :not() 在菜单上应用/取消应用边框
/* add border */
.nav li {
border-right: 1px solid #666;
}
.nav li:not(:last-child) {
border-right: 1px solid #666;
}
3. 页面顶部阴影
body:before {
content: "";
position: fixed;
top: -10px;
left: 0;
width: 100%;
height: 10px;

-webkit-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
-moz-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
box-shadow: 0px 0px 10px rgba(0,0,0,.8);

z-index: 100;
}
4.给 body 添加行高
body {
line-height: 1;
}
5.所有一切都垂直居中
html, body {
height: 100%;
margin: 0;
}

body {
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
display: -webkit-flex;
display: flex;
}
6.逗号分隔的列表
ul > li:not(:last-child)::after {
content: ",";
}
7.使用负的 nth-child 选择项目
li {
display: none;
}

/* select items 1 through 3 and display them */
li:nth-child(-n+3) {
display: block;
}
8.对图标使用 SVG
.logo {
background: url("logo.svg");
}
9.优化显示文本
html {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
}
10.对纯 CSS 滑块使用 max-height
.slider ul {
max-height: 0;
overlow: hidden;
}

.slider:hover ul {
max-height: 1000px;
transition: .3s ease;
}
11.继承 box-sizing
html {
box-sizing: border-box;
}

*, *:before, *:after {
box-sizing: inherit;
}
12.表格单元格等宽
.calendar {
table-layout: fixed;
}
13.用 Flexbox 摆脱外边距的各种 hack
.list {
display: flex;
justify-content: space-between;
}

.list .person {
flex-basis: 23%;
}
14.使用属性选择器用于空链接
a[href^="http"]:empty::before {
content: attr(href);
}
15.检测鼠标双击
HTML
<div class="test3">
<span><input type="text" value=" " readonly="true" />
<a href="http://renpingjun.com">Double click me</a></span>
</div>
CSS
.test3 span {
position: relative;
}
.test3 span a {
position: relative;
z-index: 2;
}
.test3 span a:hover, .test3 span a:active {
z-index: 4;
}
.test3 span input {
background: transparent;
border: 0;
cursor: pointer;
position: absolute;
top: -1px;
left: 0;
width: 101%; /* Hacky */
height: 301%; /* Hacky */
z-index: 3;
}
.test3 span input:focus {
background: transparent;
border: 0;
z-index: 1;
}
16.CSS 写出三角形
/* create an arrow that points up */
div.arrow-up {
width:0px;
height:0px;
border-left:5px solid transparent; /* left arrow slant */
border-right:5px solid transparent; /* right arrow slant */
border-bottom:5px solid #2f2f2f; /* bottom, add background color here */
font-size:0px;
line-height:0px;
}

/* create an arrow that points down */
div.arrow-down {
width:0px;
height:0px;
border-left:5px solid transparent;
border-right:5px solid transparent;
border-top:5px solid #2f2f2f;
font-size:0px;
line-height:0px;
}

/* create an arrow that points left */
div.arrow-left {
width:0px;
height:0px;
border-bottom:5px solid transparent; /* left arrow slant */
border-top:5px solid transparent; /* right arrow slant */
border-right:5px solid #2f2f2f; /* bottom, add background color here */
font-size:0px;
line-height:0px;
}

/* create an arrow that points right */
div.arrow-right {
width:0px;
height:0px;
border-bottom:5px solid transparent; /* left arrow slant */
border-top:5px solid transparent; /* right arrow slant */
border-left:5px solid #2f2f2f; /* bottom, add background color here */
font-size:0px;
line-height:0px;
}
17.CSS3 calc() 的使用
/* basic calc */
.simpleBlock {
width: calc(100% - 100px);
}

/* calc in calc */
.complexBlock {
width: calc(100% - 50% / 3);
padding: 5px calc(3% - 2px);
margin-left: calc(10% + 10px);
}
18.文本渐变
h2[data-text] {
position: relative;
}
h2[data-text]::after {
content: attr(data-text);
z-index: 10;
color: #e3e3e3;
position: absolute;
top: 0;
left: 0;
-webkit-mask-image: -webkit-gradient(linear, left top, left bottom, from(rgba(0,0,0,0)), color-stop(50%, rgba(0,0,0,1)), to(rgba(0,0,0,0)));}
19.禁用鼠标事件
.disabled { pointer-events: none; }
20.模糊文本
.blur {
color: transparent;
text-shadow: 0 0 5px rgba(0,0,0,0.5);
}

CSS的一些小技巧的更多相关文章

  1. css的一些小技巧。修改input样式

    在第一次正式写项目的时候,遇到了几个布局的小技巧.记录一下. 我们常常会遇到图片和文字对齐的一种样式.比如 这样的样式,我们写的时候有时候会出现不对齐的情况.我们有俩种方法 一种就是flex的布局,还 ...

  2. 关于html/css的一些小技巧之hack掉"margin-top"层叠问题

    身为小前端菜鸟一枚,忽然听到这样一则传言~~ 心情久久不能平复,想到前几日,开通了博客君,特来此寻找存在feeling~ 旨在造福普罗大众(更多前端小菜鸟) 话不多说, 我们步入正题,今天来给大家分享 ...

  3. 从零开始学习html(十五)css样式设置小技巧——下

    六.垂直居中-父元素高度确定的单行文本 <!DOCTYPE HTML> <html> <head> <meta charset="utf-8&quo ...

  4. css浮动布局小技巧

    父元素如何围住浮动的子元素的三种办法: 一.为父元素应用overflow:hidden. overflow真正用途是防止包含元素被大的内容撑开,设定了宽度之后,包含元素将超过容器的内容减掉:而它还有另 ...

  5. css的一些小技巧!页面视觉差!

    相当长的一段时间,现在网站与所谓的“视差”效果一直很受欢迎. 万一你没有听说过这种效果,不同的图像,在不同的方向移动或层主要包括.这导致了一个很好的光学效应,使参观者的注意. 在网页设计中,为了实现这 ...

  6. HTML+CSS学习笔记 (15) - css样式设置小技巧

    水平居中设置-行内元素 我们在实际工作中常会遇到需要设置水平居中场景,今天我们就来看看怎么设置水平居中的. 如果被设置元素为文本.图片等行内元素时,水平居中是通过给父元素设置 text-align:c ...

  7. HTML+CSS笔记 CSS中级 一些小技巧

    水平居中 行内元素的水平居中 </a></li> <li><a href="#">2</a></li> &l ...

  8. 一些css书写的小技巧

    一.css顺序 首先声明,浏览器读取css的方式是从上到下的.我们一般书写css只要元素具备这些属性就会达到我们预期的效果,但是这会给以后的维护和浏览器的渲染效率带来一定的影响,那么该怎么书写css的 ...

  9. 从零开始学习html(十五)css样式设置小技巧——上

    一.水平居中设置-行内元素 <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> ...

随机推荐

  1. Fuzz的那些事

    Fuzz这个词汇行内的都懂,fuzz工具我就不多说了. 今天,说说fuzz前的准备工作--如何对软件进行修改实现可自动化和无人值守fuzz. 很多软件会有试用期.弹窗.覆盖提示.人机交互等等,这些都会 ...

  2. QT数据库操作

    浏览: 在QSqlQuery类中当执行exec()后会把指针放在记录集中第一个记录之上,所以需要调用QSqlQuery::next()来获取第一个数据,下面通过循环体来遍历所有表中的数据. while ...

  3. [转]opencv3.0 鱼眼相机标定

    [原文转自]:http://blog.csdn.net/qq_15947787/article/details/51441031 前两天发表的时候没注意,代码出了点错误,所以修改了一下,重新发上来.  ...

  4. samba

    在/home/下有多个用户目录A.B...,现通过samba共享,要求A用户对A用户组目录具有root权限,对其他目录具有 读权限,B用户对B目录具有root权限,对其他目录只读.并在登陆各个目录时要 ...

  5. 【转】Android选项卡置底的方法

    转载地址:http://www.oschina.net/code/snippet_163910_6092 发现很多Android应用的选项卡 都是显示在页面底部的,网上有资料:通过反射获取TabWid ...

  6. java.sql.SQLException: 关闭的 Resultset: next

    根据异常信息判断是数据库查询出来的结果集被关闭了,所以就了next 我的代码是一个Impl方法(假设为A方法)中调用另一个Impl方法(假设为B方法),我在执行完B方法后,调用了一下关闭数据库连接的方 ...

  7. 95、Jenkins部署.net持续集成自动化测试环境

    ##目录 1. 安装Jenkins 1. 配置Jenkins 1. 自动编译 1. 自动部署 1. 自动测试 环境介绍: web服务器机器:192.168.1.7 svn服务器:192.168.1.5 ...

  8. mybatis 如何使用乐观锁

    悲观锁的问题: 因为悲观锁大多数情况下依靠数据库的锁机制实现,以保证操作最大程度的独占性.如果加锁的时间过长,其他用户长时间无法访问,影响了程序的并发访问性,同时这样对数据库性能开销影响也很大,特别是 ...

  9. Java selenium web页面的滚动条操作

    摘录自:http://blog.csdn.net/iceryan/article/details/8162703 //移动到元素element对象的"顶端"与当前窗口的" ...

  10. append追加的使用

    #!/usr/bin/env python def fun(arg) : ret = [] for i in range(len(arg)) : if i % 2 ==1 : ret.append(a ...