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. Lombok 安装、入门 - 消除冗长的 java 代码

    lombok 提供了简单的注解的形式来帮助我们简化消除一些必须有但显得很臃肿的 java 代码. lombok 的官方网址:http://projectlombok.org/  lombok 安装1. ...

  2. [转]java二维码生成与解析代码实现

    转载地址:点击打开链接 二维码,是一种采用黑白相间的平面几何图形通过相应的编码算法来记录文字.图片.网址等信息的条码图片.如下图 二维码的特点: 1.  高密度编码,信息容量大 可容纳多达1850个大 ...

  3. REST WCF Service中的WebMessageBodyStyle

    这个参数是个枚举包括如下值: WebMessageBodyStyle.Bare WebMessageBodyStyle.Wrapped WebMessageBodyStyle.WrappedReque ...

  4. Linux C 学习

    int main() { int64_t test = ; printf("%lld\n",test); float f_test = 100.2123; printf(" ...

  5. ==与equals 的使用比较

    1. == 是一个运算符. 2.Equals则是string对象的方法 我们通常是两种类型的比较 1.基本数据类型比较 2.引用对象比较 其中 1.基本数据类型比较 ==和Equals都比较两个值是否 ...

  6. sql查看锁与解锁

    select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableName from sys.dm_tran ...

  7. easyui validatebox 验证类型DEMO

    <script> $.extend($.fn.validatebox.defaults.rules, { idcard: {// 验证身份证 validator: function (va ...

  8. easyUI的Dialog和Windows框的应用

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  9. 复旦大学2015--2016学年第二学期高等代数II期末考试情况分析

    一.期末考试成绩班级前几名 胡晓波(90).杨彦婷(88).宋卓卿(85).唐指朝(84).陈建兵(83).宋沛颖(82).王昊越(81).白睿(80).韩沅伯(80).王艺楷(80).张漠林(80) ...

  10. dom节点的操作

    dom节点的操作 -- jQuery 内部插入 1.(结尾)append 方法 . appendto方法(为了方便链式操作) (开头)prepend方法           $('#div1').ap ...