淺談css中的clip裁剪用法介紹

來源:互聯網
上載者:User
clip 屬性是用來設定元素的形狀。用來剪裁絕對位置元素(absolute or fixed)。

clip有三種取值:auto |inherit|rect。inherit是繼承,ie不支援這個屬性, auto是預設 前兩個基本屬於打醬油的,我們主要來說一下clip的rect屬性。

clip的rect屬性 : clip:rect(top,right,bottom,left)四個屬性值不可缺少;

這四個屬性值到底是如何計算的呢 先看下邊這張圖

rect的top,right,bottom,left是基於左上方來計算的

來看一個小demo吧

html:

<p id="demo">      <u class="c1"></u><u class="c2"></u>   </p>

css:

#demo { position: relative; border: 1px solid #ccc; width:140px; height: 140px; padding-top: 20px; }    #demo u { width: 128px;height: 128px; position: absolute; background: url(words.png) 0 -624px no-repeat;transition: all .5s ease-in-out 0s}    #demo p { text-align: center; line-height: 120px; background: url(words.png) 400px -624px no-repeat}    #demo .c1 { clip: rect(0,128px,0,64px);}    #demo .c2 { clip:rect(128px,64px,128px,0px)}    #demo:hover>.c1 {clip:rect(0px,128px,128px,64px)}    #demo:hover>.c2 {clip:rect(0px,64px,128px,0)}

新手一枚,如有錯誤,歡迎指正。

每天進步一點點就是收穫。

以上這篇淺談css中的clip裁剪用法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援topic.alibabacloud.com。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.