Understanding CSS Clip Properties and usage

Source: Internet
Author: User
Tags codrops

A simple implementation of the clip attribute:

Style notation:

    1. . my-element {
    2. position: absolute;
    3. clip:rect (10px 350px 170px 0); / * IE4 to IE7 * /
    4. Clip:rect (10px, 350px, 170px, 0); / * ie8+ & other browsers * /
    5. }

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 即:矩形。 参数样例为:
    1. 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:

  1. <style>
  2. IMG {
  3. Position:absolute;
  4. left:10px;
  5. top:60px;
  6. Display:block;
  7. Clip:rect (200px, 0, 0, 400px);
  8. -webkit-transition:all 0.5s ease-out;
  9. -moz-transition:all 0.5s ease-out;
  10. Transition:all 0.5s ease-out;
  11. }
  12. Span:hover ~ img {
  13. Clip:rect (0, 400px, 200px, 0);
  14. }
  15. span {
  16. Display:inline-block;
  17. padding:10px;
  18. margin:10px;
  19. Background: #08C;
  20. Color:white;
  21. font-family: "Helvetica", "Arial", Sans-serif;
  22. Font-weight:bold;
  23. text-shadow:0 -1px Rgba (0,0,0,0.3);
  24. Text-align:center;
  25. Cursor:pointer;
  26. }
  27. Span:hover {
  28. Background: #09C;
  29. }
  30. </style>
  31. <span>hover me</span>
  32. <img src="Http://lorempixel.com/400/200/">

2

  1. <style>
  2. Body {
  3. Overflow:hidden;
  4. }
  5. UL {
  6. padding:0;
  7. margin:10px;
  8. List-style:none;
  9. width:300px;
  10. height:300px;
  11. box-shadow:0 0 10px Rgba (0,0,0,0.5);
  12. }
  13. Ul:after {
  14. Clear:both;
  15. Content: "";
  16. display:table;
  17. }
  18. Li {
  19. position:relative;
  20. Float:left;
  21. width:100px;
  22. height:100px;
  23. Background:url (' http://subtlepatterns.subtlepatterns.netdna-cdn.com/patterns/pw_maze_white.png ');
  24. Cursor:pointer;
  25. }
  26. Li:nth-of-type (3n+1) {
  27. Clear:both;
  28. }
  29. IMG {
  30. Position:absolute;
  31. Display:block;
  32. Clip:rect (0, 100px, 100px, 0);
  33. -webkit-transition:all 0.2s ease-out, z-index 0s;
  34. -moz-transition:all 0.2s ease-out, z-index 0s;
  35. Transition:all 0.2s ease-out, z-index 0s;
  36. opacity:0.9;
  37. }
  38. Li:hover img {
  39. Clip:rect (0, 300px, 300px, 0);
  40. Z-index:2;
  41. Opacity:1;
  42. }
  43. Li:nth-of-type (3n+1): hover img {
  44. left:310px;
  45. }
  46. Li:nth-of-type (3n+2): hover img {
  47. left:210px;
  48. }
  49. Li:nth-of-type (3n): hover img {
  50. left:110px;
  51. }
  52. Li:nth-of-type (n+4): Nth-of-type (-n+6): hover img {
  53. Top: -100px;
  54. }
  55. Li:nth-of-type (n+7): Nth-of-type (-n+9): hover img {
  56. Top: -200px;
  57. }
  58. </style>
  59. <ul>
  60. <li><img src="http://lorempixel.com/300/300/sports/"></ li>
  61. <li><img src="http://lorempixel.com/300/300/animals/"></ Li>
  62. <li><img src="http://lorempixel.com/300/300/abstract/"> </li>
  63. <li><img src="http://lorempixel.com/300/300/nightlife/"></ li>
  64. <li><img src="http://lorempixel.com/300/300/city/"> </li>
  65. <li><img src="http://lorempixel.com/300/300/food/"></li >
  66. <li><img src="http://lorempixel.com/300/300/people/"> </li>
  67. <li><img src="http://lorempixel.com/300/300/nature/"></ Li>
  68. <li><img src="http://lorempixel.com/300/300/fashion/"> </li>
  69. </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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.