'Why the clip property only works on elements with position: absolute or position: fixed
Why the clip property only works on elements with position: absolute or position: fixed. Why it won’t work with relative or static positioning. heres is my code. Fiddle
<span>Hover me</span>
<img src="http://sambuh.com/assets/images/news%20headlines/bukhara-autumn1.jpg">
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(0px, 400px, 400px, 0);
}
Solution 1:[1]
For your question need to understand the difference between various css positioning properties.
Here is some Useful Links:
Solution 2:[2]
clip:rect(0, 0, 0, 0) is deprecated, you should use: clip-path:inset(0 0 0 0), it works with relative positioning.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vaibhav Jain |
| Solution 2 | Mirko |
