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 ...
随机推荐
- Java 中 ThreadLocal 内存泄露的实例分析
前言 之前写了一篇深入分析 ThreadLocal 内存泄漏问题是从理论上分析ThreadLocal的内存泄漏问题,这一篇文章我们来分析一下实际的内存泄漏案例.分析问题的过程比结果更重要,理论结合实际 ...
- 解决Ubuntu "E: 软件包 vim 还没有可供安装的候选者"问题
sudo apt-get update 试着运行这段代码后再尝试sudo apt-get install 安装语句
- MWeb 2.0.7 版发布!
更新前针对 MAS 上的评论重点说一下:MWeb 是支持直接对本地文件夹操作的,不用导入到文档库!请使用外部模式!请使用外部模式!!请使用外部模式!!! 重要的话讲三次!使用方法是 CMD + E 打 ...
- C语言第三次作业
#include<stdio.h>//1.三角形 int main() { printf("*\n"); printf("**\n"); print ...
- No Spring WebApplicationInitializer types detected on classpath。启动时不报错,但是页面打不开。
一片红,没有黑色disPatcher的加载. 百度,但是没有用,二十分钟浪费,这个问题的本质就是web.xml中的disPatcher没有加载,但是我肯定和代码无关,配置文件也没有变化过,值可能是to ...
- WPF中弹出文件夹浏览对话框
附一个共享目录正则表达式判断: bool result= System.Text.RegularExpressions.Regex.IsMatch("\\pc-test\share" ...
- 2.4 C#的变量
在C#中,不仅有常量,还有变量,而且最常用的还是变量.下面是变量的知识. C#的变量有3个步骤:声明.赋值.使用. 变量声明的方法:数据类型 变量名; 变量赋值的方法:变量名=变量的值: 下面是这3个 ...
- JsonUtil工具类
package comm; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collec ...
- Delphi Json
superobject.pas单元对json的解析非常方便, 力荐 下面演示对如下json的解析 { ", "memo": "S.H.E 004" } ...
- 使用FastJSON,将对象或数组和JSON串互转
Fastjson,是阿里巴巴提供的一个Java语言编写的高性能功能完善的JSON库.其开源的下载网址为:https://github.com/AlibabaTech/fastjson. 示例代码如下: ...