


What is the clip attribute in css? clip:rect() creates circular progress bar animation (code example)
This chapter will tell you what is the clip attribute in CSS? clip:rect() creates a circular progress bar animation (code example), introduces to you what the clip attribute is, the usage of clip:rec(), and finally uses an example to let you understand clip:rect() more intuitively. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. What is the clip attribute in css?
clip property clips absolutely positioned elements. The clip attribute allows defining the visible size of an element. When an image is larger than the size of the element it contains, the image will be clipped and displayed as the shape defined by the element.
1. Grammar
img { position:absolute; clip:rect(0px,60px,200px,0px); }
Code example:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> .demo{ width: 200px; height: 500px; margin: 50px auto; } img{ border: 1px solid #000; } .img { position:absolute; clip:rect(0px,165px,200px,34px); } </style> </head> <body> <div class="demo"> <h4 id="原图">原图:</h4> <img src="/static/imghw/default1.png" data-src="css.jpg" class="lazy" style="max-width:90%" style="max-width:90%" / alt="What is the clip attribute in css? clip:rect() creates circular progress bar animation (code example)" > <h4 id="裁剪后">裁剪后</h4> <img class="img lazy" src="/static/imghw/default1.png" data-src="css.jpg" style="max-width:90%" style="max-width:90%" / alt="What is the clip attribute in css? clip:rect() creates circular progress bar animation (code example)" > </div> </body> </html>
Rendering:
0px, 165px, 200px, and 34px in clip:rect(0px, 165px, 200px, 34px) respectively correspond to the top, right, bottom, and left directions of the image; clip:rect() needs to be used with the position attribute to adjust the image Make a cut.
Note:
If an element is defined with "overflow: visible" first, the clip attribute will not work.
clip:rect() in css can only be used on absolutely positioned elements, including elements with fixed attributes, because fixed is also considered absolute positioning
2. Usability hiding
According to the above explanation of top right bottom left, if left >= right or bottom <= top, the element will be completely cropped Falling out of sight, that is, "hiding". Elements hidden in this way are visible to assistive devices such as screen readers, thus improving the usability of the page.
2. Create circular progress bar animation with css3 (css3 animation is used in combination with clip:rect())
Let’s take a look at the loading effect first Picture:
Code example:
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>css3制作圆形进度条动画</title> <style> * { margin: 0; padding: 0; } body { overflow-x: hidden; overflow-y: scroll; font-family: MuseoSans, Georgia, "Times New Roman", Times, serif; font-size: 13px; color: #444; border-top: 3px solid #444; background-color: #E4E6E5; overflow-x: hidden; } section .demo { width: 530px; margin: 15em auto; overflow: hidden; } ul.notes { clear: both; } ul.notes li { float: left; margin-right: 3em; display: inline; } ul.notes li:last-child { margin: 0; } ul.notes li span.skill { display: block; text-align: center; padding: 10px 0; text-shadow: 1px 0 0 #FFFFFF; } .notesite { display: inline-block; position: relative; width: 1em; height: 1em; font-size: 5.4em; cursor: default; } .notesite>.percent { position: absolute; top: 20px; left: 0; width: 100%; font-size: 25px; text-align: center; z-index: 2; } .notesite>.percent .dec { font-size: 15px; } .notesite>#slice { position: absolute; width: 1em; height: 1em; clip: rect(0px, 1em, 1em, 0.5em); } .notesite>#slice.gt50 { clip: rect(auto, auto, auto, auto); } .notesite>#slice>.pie { position: absolute; border: 0.1em solid #444; width: 0.8em; height: 0.8em; -moz-border-radius: 0.5em; -webkit-border-radius: 0.5em; border-radius: 0.5em; -webkit-animation: craw 2s linear; -webkit-animation-iteration-count: 1; } @-webkit-keyframes craw { 0% { clip: rect(0em, 1em, 0em, 0.5em); } 50% { clip: rect(0em, 1em, 1em, 0.5em); -webkit-transform: rotate(0deg); -moz-transform: rotate(0deg); -ms-transform: rotate(0deg); -o-transform: rotate(0deg); transform: rotate(0deg); } 100% { clip: rect(0em, 1em, 1em, 0em); -webkit-transform: rotate(90deg); -moz-transform: rotate(90deg); -ms-transform: rotate(90deg); -o-transform: rotate(90deg); transform: rotate(90deg); } } li.html .notesite>#slice>.pie { border-color: #DF6C4F; } .notesite.fill>.percent { display: none; } li.html .notesite:before { background: #DF6C4F; } </style> </head> <body class="home"> <div class="wrapper"> <section> <div class="demo"> <ul class="notes"> <li class="html"> <div class="notesite" id="note_0" dir="100"> <div class="percent"></div> <div id="slice" class="gt50"> <div class="pie fill"> </div> </div> </div><span class="skill">HTML</span> </li> </ul> </div> </section> </div> </body> </html>
Idea:
1. First draw a square border
2. Make it a circle through the border-radius attribute (considering compatibility)
-moz-border-radius: 0.5em; -webkit-border-radius: 0.5em; border-radius: 0.5em;
3. Set animation effects, By changing the clipping position (combined with positioning), the circle slowly appears
@-webkit-keyframes craw { 0% { clip: rect(0em, 1em, 0em, 0.5em); } 50% { clip: rect(0em, 1em, 1em, 0.5em); -webkit-transform: rotate(0deg); -moz-transform: rotate(0deg); -ms-transform: rotate(0deg); -o-transform: rotate(0deg); transform: rotate(0deg); } 100% { clip: rect(0em, 1em, 1em, 0em); -webkit-transform: rotate(90deg); -moz-transform: rotate(90deg); -ms-transform: rotate(90deg); -o-transform: rotate(90deg); transform: rotate(90deg); } }
The above is the detailed content of What is the clip attribute in css? clip:rect() creates circular progress bar animation (code example). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text
