標籤:style class code http ext color
應用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 } ;auto 即瀏覽器預設解析,無clip效果,inderit 繼承父層clip樣式
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/