css的小技巧
前几天看到《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的小技巧的更多相关文章
- 第八十四节,css布局小技巧及font-awesome图标使用
css布局小技巧及font-awesome图标使用 图片鼠标放上去遮罩效果,显示文字 当鼠标放上去时 /*最外层div*/ .a{ width: 384px; height: 240px; backg ...
- css样式小技巧
1.css样式小技巧 HTML怎样设定使背景图片不随页面滚动而滚动 background-attachment:fixed; 2.实现li a 超过长度内容出现省略号… overflow:hidden ...
- CSS 黑魔法小技巧,让你少写不必要的JS,代码更优雅
首页 登录注册 CSS 黑魔法小技巧,让你少写不必要的JS,代码更优雅 阅读 8113 收藏 927 2017-09-26 原文链接:github.com 腾讯云容器服务CSS,立 ...
- html/css/js小技巧实例
一些学习中碰到的小技巧 让div自动撑起来: .clearfix:after{ content: "."; clear: both; display: block; visibil ...
- 一些常用的html/CSS效果---小技巧
我常用的重置样式表reset.css /*===============基础信息================*/ *{border: 0;padding: 0;margin: 0;} table ...
- CSS调试小技巧 —— 调试DOM元素hover,focus,actived的样式
最近学习html5和一些UI框架,接触css比较多,就来跟大家分享一下css中的一些调试技巧.之前做页面,css都是自己写的,所以要改哪里可以很快的找到,现在使用了UI框架,里面的样式是不可能读完的, ...
- CSS设置小技巧
水平居中 对于元素的水平居中,有三种情况: 行内元素(文字.图片等):text-align: center; 定宽块状元素(有设置宽度的block元素):margin: 0 auto; 不定宽块状元素 ...
- 【温故知新】——CSS黑魔法小技巧可以少些不必要的js
前言:这篇文章是转载[前端开发博客]的一篇技术文章,并非本人所写.只是个人觉得很实用,所以分享给大家.原文链接:github.com 1.利用 CSS 的 content 属性 attr 抓取资料需求 ...
- CSS定位小技巧
CSS定位Static 默认定位Relative 相对定位:left 和topposition: relative;/*相对定位*/ left:40px;/*在原来的位置向右移动*/ top:100p ...
随机推荐
- Thinkphp 中 distinct 的用法
TP中distinct()的用处主要是去除重复的值 在Thinkphp手册中也详细说明了(链接:http://document.thinkphp.cn/manual_3_2.html#distinct ...
- linux-------------计划任务crond:如何创建linux里面的计划任务
1.centos下安装crond [root@localhost /]# yum -y install vixie-cron [root@localhost /]# yum -y install cr ...
- 论文阅读(Xiang Bai——【CVPR2016】Multi-Oriented Text Detection with Fully Convolutional Networks)
Xiang Bai--[CVPR2016]Multi-Oriented Text Detection with Fully Convolutional Networks 目录 作者和相关链接 方法概括 ...
- 如何使用iTunes与iTools导出微信聊天记录
.tocblock .tocblock .tocblock { margin-left: 2.25em; } .madoko .toc>.tocblock .tocblock { margin- ...
- Oracle11完全卸载
1.停用oracle服务:进入计算机管理,在服务中,找到oracle开头的所有服务,右击选择停止 2.在开始菜单中,找到Universal Installer,运行Oracle Universal I ...
- jQuery属性操作
jQuery 的属性操作的核心部分其实就是对底层 getAttribute().setAttributes()等方法的一系列兼容性处理 ...if ( notxml ) { name = name.t ...
- wex5 实战 框架拓展之1 公共data组件(Data)
一 前言 wex5作为开发利器,框架本身的集成能力与拓展能力可谓简单强大.在学习过程中,对框架的拓展能力,需要通过实践来丰富.今天,我以实际工作中的实例,先来看一看,框架上的公共data组件的实现与用 ...
- session原理及实现共享
一.session的本质http协议是无状态的,即你连续访问某个网页100次和访问1次对服务器来说是没有区别对待的,因为它记不住你.那么,在一些场合,确实需要服务器记住当前用户怎么办?比如用户登录邮箱 ...
- Python 对目录中的文件进行批量转码(GBK>UTF8)
通过python实现对文件转码,其实处理很简单: 1.打开读取文件内容到一个字符串变量中,把gbk编码文件,对字符串进行decode转换成unicode 2.然后使用encode转换成utf-8格式. ...
- Android多媒体--MediaCodec 中文API文档
*由于工作需要,需要利用MediaCodec实现Playback及Transcode等功能,故在学习过程中翻译了Google官方的MediaCodec API文档,由于作者水平限制,文中难免有错误和不 ...