你可以使用简单的 CSS 和渐变,而不用介意容器或 img 的大小:DEMO
div, img {
margin:1em;
display:inline-block;
padding:0.5em;
vertical-align:top;
border-radius:10px;
background:linear-gradient(to left,black 33.33%,transparent 40% ,transparent 50%,black 66.66%) 0 0 repeat-x, linear-gradient(to right,black 33.33%,transparent 40% ,transparent 50%, black 66.66%) 100% 100% repeat-x, linear-gradient(to top,black 33.33%,transparent 40% ,transparent 50%, black 66.66%) 0 100% repeat-y, linear-gradient(to bottom,black 33.33%,transparent 40% ,transparent 50%, black 66.66%) 100% 0 repeat-y, linear-gradient(to bottom right,turquoise,white,lime) center no-repeat ;
background-color:gray;
background-size:300% 5px,300% 5px,5px 300%,5px 300%,100% 100%;
transition:1.5s linear;
}
div:hover { background-position:100% 0 ,0% 100%, 0 0 , 100% 100%, 0 0 ;}
可能的标记
<div>
<h1> border transition</h1>
<p>text</p>
</div>
<img src="http://lorempixel.com/200/150/"/>