理解CSS Clip属性及用法
应用Clip属性实现的一个简单效果图:
样式写法:
- .my-element {
- position: absolute;
- clip: rect(10px 350px 170px 0); /* IE4 to IE7 */
- clip: rect(10px, 350px, 170px, 0); /* IE8+ & other browsers */
- }
属性解析:
clip
: { shape |
auto
| inherit } ;
shape 设置clip 形状,目前只支持 rect 即:矩形。 参数样例为:
- clip: rect(<top>, <right>, <bottom>, <left>);
有点不足的是 clip 属性只能使用于 位置属性设置为 absolute 或 fixed的元素
使用Clip实现的范例:
- <style>
- img {
- position: absolute;
- left: 10px;
- top: 60px;
- display: block;
- clip: rect(200px, 0, 0, 400px);
- -webkit-transition: all 0.5s ease-out;
- -moz-transition: all 0.5s ease-out;
- transition: all 0.5s ease-out;
- }
- span:hover ~ img {
- clip: rect(0, 400px, 200px, 0);
- }
- span {
- display: inline-block;
- padding: 10px;
- margin: 10px;
- background: #08C;
- color: white;
- font-family: "Helvetica", "Arial", sans-serif;
- font-weight: bold;
- text-shadow: 0 -1px rgba(0,0,0,0.3);
- text-align: center;
- cursor: pointer;
- }
- span:hover {
- background: #09C;
- }
- </style>
- <span>Hover me</span>
- <img src="http://lorempixel.com/400/200/">
2
- <style>
- body {
- overflow: hidden;
- }
- ul {
- padding: 0;
- margin: 10px;
- list-style: none;
- width: 300px;
- height: 300px;
- box-shadow: 0 0 10px rgba(0,0,0,0.5);
- }
- ul:after {
- clear: both;
- content: "";
- display: table;
- }
- li {
- position: relative;
- float: left;
- width: 100px;
- height: 100px;
- background: url(' http://subtlepatterns.subtlepatterns.netdna-cdn.com/patterns/pw_maze_white.png');
- cursor: pointer;
- }
- li:nth-of-type(3n+1) {
- clear: both;
- }
- img {
- position: absolute;
- display: block;
- clip: rect(0, 100px, 100px, 0);
- -webkit-transition: all 0.2s ease-out, z-index 0s;
- -moz-transition: all 0.2s ease-out, z-index 0s;
- transition: all 0.2s ease-out, z-index 0s;
- opacity: 0.9;
- }
- li:hover img {
- clip: rect(0, 300px, 300px, 0);
- z-index: 2;
- opacity: 1;
- }
- li:nth-of-type(3n+1):hover img {
- left: 310px;
- }
- li:nth-of-type(3n+2):hover img {
- left: 210px;
- }
- li:nth-of-type(3n):hover img {
- left: 110px;
- }
- li:nth-of-type(n+4):nth-of-type(-n+6):hover img {
- top: -100px;
- }
- li:nth-of-type(n+7):nth-of-type(-n+9):hover img {
- top: -200px;
- }
- </style>
- <ul>
- <li><img src="http://lorempixel.com/300/300/sports/"></li>
- <li><img src="http://lorempixel.com/300/300/animals/"></li>
- <li><img src="http://lorempixel.com/300/300/abstract/"></li>
- <li><img src="http://lorempixel.com/300/300/nightlife/"></li>
- <li><img src="http://lorempixel.com/300/300/city/"></li>
- <li><img src="http://lorempixel.com/300/300/food/"></li>
- <li><img src="http://lorempixel.com/300/300/people/"></li>
- <li><img src="http://lorempixel.com/300/300/nature/"></li>
- <li><img src="http://lorempixel.com/300/300/fashion/"></li>
- </ul>
关于Clip属性应用的进阶使用范例: http://tympanus.net/codrops/2013/01/17/putting-css-clip-to-work-expanding-overlay-effect/
参考网址: http://tympanus.net/codrops/2013/01/16/understanding-the-css-clip-property/
理解CSS Clip属性及用法的更多相关文章
- CSS Clip属性
Clip属性在W3C官网是这样进行描述的:“通过对元素进行剪切来控制元素的可显示区域,默认情况下,元素是不进行任何剪切的,但是也有可能剪切区域也显示的设置了clip属性”. .selector { c ...
- 将CSS CLIP属性应用在:扩展覆盖效果
我们想要展示如何利用CSS3 clip属性制作一种简单而整洁的扩展效果,当点击一个box元素时实现平稳过渡.这个想法是为了实现某种叠加效果,好像它实际上在各个元素的下面.点击其中一个元素将创建一个切断 ...
- CSS margin属性与用法教程
margin 属性是css用于在一个声明中设置所有 margin 属性的简写属性,margin是css控制块级元素之间的距离, 它们之间是透明不可见的. margin属性包含了margin left ...
- JS控制css float属性的用法经验总结
JavaScript与CSS属性的控制网上很常见,因此来说用js操作css属性是有一定规律的. 1.对于没有中划线的css属性一般直接使用style.属性名即可. 如:obj.style.margin ...
- CSS Clip剪切元素动画实例
1.CSS .fixed { position: fixed; width: 90px; height: 90px; background: red; border: 0px solid blue; ...
- WPF 用Clip属性实现蒙板特效
原文:WPF 用Clip属性实现蒙板特效 上一篇,已简单介绍Clip属性的用法,这一篇用它来实现简单蒙板功能,很简单,直接上代码 <Window x:Class="擦除效果.MainW ...
- 关于CSS的table-layout属性的用法详解
前言: 今天来和大家详细说一下table-layout属性的用法. /*eg:设置表格布局算法*/ table{ table-layout:fixed; } ***本文关键词:table-layout ...
- 深入理解css中的margin属性
深入理解css中的margin属性 之前我一直认为margin属性是一个非常简单的属性,但是最近做项目时遇到了一些问题,才发现margin属性还是有一些“坑”的,下面我会介绍margin的基本知识以及 ...
- 深入理解css中position属性及z-index属性
深入理解css中position属性及z-index属性 在网页设计中,position属性的使用是非常重要的.有时如果不能认识清楚这个属性,将会给我们带来很多意想不到的困难. position属性共 ...
随机推荐
- Spark 中的join方式(pySpark)
spark基础知识请参考spark官网:http://spark.apache.org/docs/1.2.1/quick-start.html 无论是mapreduce还是spark ,分布式框架的性 ...
- 杭州(含嘉兴,绍兴,金华,湖州,义乌)Uber优步司机奖励政策(1月25日~1月31日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- poj 1789 Truck History【最小生成树prime】
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21518 Accepted: 8367 De ...
- C# 光标文件的创建
base.m_cursor = new System.Windows.Forms.Cursor(GetType(), "Resources.MeasuredisTool.cur") ...
- ll 详解
长选项必须使用的参数对于短选项时也是必需使用的. -a, --all 不隐藏任何以. 开始的项目 -A, --almost-all ...
- (转)Linux中的文件描述符
本文转自:http://blog.csdn.net/cywosp/article/details/38965239 作者:cywosp 1. 概述 在Linux系统中一切皆可以看成是文件,文件又可分为 ...
- 转 MySQL 用户权限详细汇总
http://blog.csdn.net/mchdba/article/details/45934981 1,MySQL权限体系 MySQL 的权限体系大致分为5个层级: 全局层级: 全局权限适用于一 ...
- 移动开发框架,第【一】弹:QuoJs 官方文档(汉化版)
作者:一只猿 原文地址: http://www.92ez.com 转载请注明出处,谢谢 帮助说明 如果您认为QuoJS只是一个触摸事件管理器,那你就错了,它是一个功能丰富的类库,无需第三方JavaSc ...
- js 解析 bytearray 成 字符串
function bin2String(array) { return String.fromCharCode.apply(String, array); } var bit=[104,101,108 ...
- linux内核学习-建议路线
三大经典书: LDD: Linux Device Driver 容易上手 LKD: Linux Kernel Development 通俗易懂 UDK: Understand Linux Kernel ...