前几天看到《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. linux查看进程启动时间

    1. ps axu 2. 精确查看 for pid in $(pgrep httpd); do echo -n "${pid} " ; ps -p ${pid} -o lstart ...

  2. kali 更改root密码

    sudo root passwd root 然后输入两次密码即可

  3. No compiler is provided in this environment. Perhaps you are running on a JRE ra

    No compiler is provided in this environment. Perhaps you are running on a JRE ra,有需要的朋友可以参考下. 控制台输出的 ...

  4. AppSettings从数据库读取

    /// <summary> /// 提供对配置信息的访问 /// </summary> public static class AppSettings { /// <su ...

  5. jquery 获取父窗口的元素 父窗口 子窗口

    一.获取页面元素 取父窗口的元素方法:$(selector, window.parent.document); 那么你取父窗口的父窗口的元素就可以用:$(selector, window.parent ...

  6. Jenkins Slave 通过JNLP 的方式 访问Master IP 总是127.0.0.1

    解决办法,重启机器 可能是我以前用的jenkins url 是127.0.0.1 然后是缓存什么没有释放掉所致 <jnlp codebase="http://183.62.104.48 ...

  7. CF 484E - Sign on Fence

    E. Sign on Fence time limit per test 4 seconds memory limit per test 256 megabytes input standard in ...

  8. ubuntu安装cpu版caffe

    最近在笔记本上配置了ubuntu14.04,并配置了caffe,整个过程大概花了2个小时. 希望在安装时能给大家一个启发,这里配置的是无gpu版的,因为我的笔记本时核心显卡,配置gpu版的要编译cud ...

  9. 003_关于IntellJ IDE 2016 1. 4的使用

    IDEA 全称 IntelliJ IDEA,是java语言开发的集成环境,IntelliJ在业界被公认为最好的java开发工具之一,尤其在智能代码助手.代码自动提示.重构.J2EE支持.各类版本工具( ...

  10. “You couldn’t see my tears cause I am in the water.“ Fish said to water.“But I could feel your tears cause you are in my heart..“ Answered water.

    “You couldn’t see my tears cause I am in the water.“ Fish said to water.“But I could feel your tears ...