CSS3 to achieve a picture corner effect example

Source: Internet
Author: User


Effect analysis

Let's say we set the width and height of an element to 0, then set the border to 80px, and the top and bottom borders are two different colors, respectively.

That

width:0;
height:0;
border:80px solid;
Border-color: #00a67c #333;

As we can see, the four borders are pieced together like four triangles (obviously we can make a triangle by setting a single border)

To play the picture, four borders are four triangles together to form a square, what if it's set to two borders?

Would it be two triangles to synthesize a square? It turned out to be true!

CSS Code:
. border {
width:0;
height:0;
border:0px solid;
Border-color: #00a67c #333;
Float:left;
margin-left:10px;
}
. border1 {
border-left-width:80px;
border-top-width:80px;
}
. border2 {
border-left-width:80px;
border-bottom-width:80px;
}
. border3 {
border-right-width:80px;
border-top-width:80px;
}
. border4 {
border-right-width:80px;
border-bottom-width:80px;
}

HTML Code:

<div class= "Border Border1" ></div>
<div class= "Border Border2" ></div>
<div class= "Border Border3" ></div>
<div class= "Border Border4" ></div>

Here are four ways to remove two borders:

Smart students may have found that the corner effect is actually two triangular combination of squares, the effect of the formation, of course, also need to adjust the transparency of the color and so on.

Here is to achieve the upper right corner of the corner effect, so we need to select the fourth effect in the above figure.

Another point to add,

Adding a corner effect is actually in the top layer of the picture added, so use the pseudo element: before

Final code example

CSS Code
. image-layer {
width:384px;
height:240px;
margin:40px Auto 0;
position:relative;
Cursor:pointer;
Overflow:hidden;
}
. image-layer:before {
Content: ';
Position:absolute;
top:0;
right:0;
border:0px solid;
Border-color:rgba (0, 0, 0, 0.2) #fff;
-webkit-transition:border 5s ease;
}
. image-layer:hover:before {
border-right-width:80px;
border-bottom-width:80px
}

HTML Code

<div class= "Image-layer" id= "Image-layer" >

</div>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.