前几天看到《css揭秘》这本书,第一感觉是 css怎么能出这么厚的一本书,不过 细细一想,用好css真的可以实现很多想要的效果,节省很多js代码。

总结几个css的小技巧:

1,将所有元素垂直居中

 html, body {
height: 100%;
margin:;
} body {
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
display: -webkit-flex;
display: flex;
}

IE11、Firefox、Chrome 和 Opera 支持 align-items 属性。

Safari、IE 9 及其之前的版本不支持 align-items 属性。IE 10 需要前缀 -ms-。

任何一个容器都可以指定为Flex布局。行内元素也可以使用Flex布局。(display: inline-flex;)

Webkit内核的浏览器,必须加上-webkit前缀。

2,表格单元格等宽:

 .calendar {
table-layout: fixed;
}

3,使用属性选择器用于空链接:

当a元素没有文本值,但 href 属性有链接的时候显示链接:

 a[href^="http"]:empty::before {
content: attr(href);
}

4,检测鼠标双击:

HTML:

readonly:输入字段为只读
 <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:;
}
.test3 span a:hover, .test3 span a:active {
z-index:;
}
.test3 span input {
background: transparent;
border:;
cursor: pointer;
position: absolute;
top: -1px;
left:;
width: 101%; /* Hacky */
height: 301%; /* Hacky */
z-index:;
}
.test3 span input:focus {
background: transparent;
border:;
z-index:;
}

5,CSS 写出三角形:

利用border来写三角形代码,并且兼容IE6.

 /* 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;
}

6,文本渐变:

 h2[data-text] {
position: relative;
}
h2[data-text]::after {
content: attr(data-text);
z-index:;
color: #e3e3e3;
position: absolute;
top:;
left:;
-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)));}

7,禁用鼠标事件:

CSS3 新增的 pointer-events 让你能够禁用元素的鼠标事件,例如,一个连接如果设置了下面的样式就无法点击了。

 .disabled { pointer-events: none; }

8,模糊文本:

 .blur {
color: transparent; text-shadow: 0 0 5px rgba(0,0,0,0.5);
}

css的小技巧的更多相关文章

  1. 第八十四节,css布局小技巧及font-awesome图标使用

    css布局小技巧及font-awesome图标使用 图片鼠标放上去遮罩效果,显示文字 当鼠标放上去时 /*最外层div*/ .a{ width: 384px; height: 240px; backg ...

  2. css样式小技巧

    1.css样式小技巧 HTML怎样设定使背景图片不随页面滚动而滚动 background-attachment:fixed; 2.实现li a 超过长度内容出现省略号… overflow:hidden ...

  3. CSS 黑魔法小技巧,让你少写不必要的JS,代码更优雅

    首页   登录注册         CSS 黑魔法小技巧,让你少写不必要的JS,代码更优雅 阅读 8113 收藏 927 2017-09-26 原文链接:github.com 腾讯云容器服务CSS,立 ...

  4. html/css/js小技巧实例

    一些学习中碰到的小技巧 让div自动撑起来: .clearfix:after{ content: "."; clear: both; display: block; visibil ...

  5. 一些常用的html/CSS效果---小技巧

    我常用的重置样式表reset.css /*===============基础信息================*/ *{border: 0;padding: 0;margin: 0;} table ...

  6. CSS调试小技巧 —— 调试DOM元素hover,focus,actived的样式

    最近学习html5和一些UI框架,接触css比较多,就来跟大家分享一下css中的一些调试技巧.之前做页面,css都是自己写的,所以要改哪里可以很快的找到,现在使用了UI框架,里面的样式是不可能读完的, ...

  7. CSS设置小技巧

    水平居中 对于元素的水平居中,有三种情况: 行内元素(文字.图片等):text-align: center; 定宽块状元素(有设置宽度的block元素):margin: 0 auto; 不定宽块状元素 ...

  8. 【温故知新】——CSS黑魔法小技巧可以少些不必要的js

    前言:这篇文章是转载[前端开发博客]的一篇技术文章,并非本人所写.只是个人觉得很实用,所以分享给大家.原文链接:github.com 1.利用 CSS 的 content 属性 attr 抓取资料需求 ...

  9. CSS定位小技巧

    CSS定位Static 默认定位Relative 相对定位:left 和topposition: relative;/*相对定位*/ left:40px;/*在原来的位置向右移动*/ top:100p ...

随机推荐

  1. io与nio的区别

    传统的socket IO中,需要为每个连接创建一个线程,当并发的连接数量非常巨大时,线程所占用的栈内存和CPU线程切换的开销将非常巨大.使用NIO,不再需要为每个线程创建单独的线程,可以用一个含有限数 ...

  2. hdu5219 Repeating

    后缀数组+莫比乌斯函数 #include <stdio.h> #include <string.h> #include<algorithm> using names ...

  3. (一)Nand FLASH 原理讲解

    NAND FLASH  优势 : 可以用当硬盘   这里好像型号是 K9F2G08 基本结构: 不是很难自己看看,暂时不要看

  4. 在nginx日志的access log中记录post请求的参数值

    背景:有时程序偶出现参数少了或没有提交到下一个链接Url里后出现问题,如何查呢,最好的办法是在nginx上的加post参数,以定位到问题才有可能对某个UIR的代码出现的问题进行排查. og_forma ...

  5. js执行环境的深入理解

    第一个例子中 :之所以每个函数都返回不同的值的原因 有2点 (简写如下文) 就是[SCOPE]内部属性,函数可能拥有相同的父作用域时,多个函数引用同一个[SCOPE]属性,所以return i的值还是 ...

  6. 老贼博客php教程从零学习PHP开始写作,顺祝新同事快乐!

    随笔是不是这样写的,好似是吧! 老贼博客php教程从零学习PHP开始写作,顺祝新同事快乐! 谢谢支持,点赞!

  7. SourceInsight阅读Python---张子芳

    首先从http://www.sourceinsight.com/public/languages/下载Python的配置文件Python.CLF ,然后对SourceInsight作如下配置: (1) ...

  8. java布局学习 (二)

    前文中介绍了FlowLayout和BorderLayout 本文我们将会继续介绍java中的布局方式 (3)GridLayout 网格布局 这种布局会将整个容器划分成M行*N列的网格. 如下图:    ...

  9. Keras学习~试用卷积~跑CIFAR-10

    import numpy as np import cPickle import keras as ks from keras.layers import Dense, Activation, Fla ...

  10. Core 1.0中publishOptions Include的bug

    "publishOptions": { "include": [ "wwwroot", "Views", "A ...