css - Restrict a click to a specific shape -


i have image/polygon defined in css this:

.post-wrapper {     position: relative;     width: 250px;     height: 420px;     float: left;     background-color: #ddc;     -webkit-clip-path: polygon(50% 100%, 100% 50%, 50% 0, 0 50%);     -webkit-background-size: cover;     -moz-background-size: cover;     -o-background-size: cover;     background-size: cover;  } 

you can see image:

maintain click event in css shape

it defines sort of rectangle, clickable image redirects page, , people able click in part of rectangle want them click on polygon. knows how can here in code?

fidde

css solution

you may maintain boundaries of diamond shape , make part image clickable using css transform properties. point use skew property link actualy has diamond shape , therefore isn't clickable outside shape (see following demo , screenshot). then, need "counter transform" content isn't skewed.

demo

screenshot :

diamond shape proper boundaries

relevant css :

a{     width: 216px;     height: 250px;     overflow:hidden;     display:inline-block;     background:red;      -webkit-backface-visibility:hidden; /* reduce pixelisation on borders in chrome */      -webkit-transform-origin:0 0;     -ms-transform-origin:0 0;     transform-origin:0 0;       -webkit-transform: translate(55%,0) rotate(30deg) skewy(30deg);     -ms-transform: translate(55%,0) rotate(30deg) skewy(30deg);     transform: translate(55%,0) rotate(30deg) skewy(30deg); }  .post-wrapper {     width: 250px;     height: 432px;     background: url(http://lorempixel.com/output/people-h-c-250-432-8.jpg) center center;     background-size: cover;       -webkit-transform-origin:0 0;     -ms-transform-origin:0 0;     transform-origin:0 0;      -webkit-transform:   skewy(-30deg) rotate(-30deg) translate(-50%,0);     -ms-transform:   skewy(-30deg) rotate(-30deg) translate(-50%,0);     transform:   skewy(-30deg) rotate(-30deg) translate(-50%,0); } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -