A simple implementation of the clip attribute:
Style notation:
- . my-element {
- position: absolute;
- clip:rect (10px 350px 170px 0); / * IE4 to IE7 * /
- Clip:rect (10px, 350px, 170px, 0); / * ie8+ & other browsers * /
- }
Attribute parsing:
clip
: { shape |
auto
| inherit } ;
Auto is the browser default parsing, no clip effect, inderit inherit the parent layer clip style
shape 设置clip 形状,目前只支持 rect 即:矩形。 参数样例为:
- Clip:rect (<Top>, <Right>, <Bottom>, <left>);
A bit of a disadvantage is that the clip property can only be used to set the Position property to absolute or fixed elements
Examples of using clip implementation:
- <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>
Advanced usage Example for clip attribute application: http://tympanus.net/codrops/2013/01/17/putting-css-clip-to-work-expanding-overlay-effect/
Reference URL: http://tympanus.net/codrops/2013/01/16/understanding-the-css-clip-property/