Cut out shape (triangle) from div and show background behind [closed] - html

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I am trying to cut a triangle out of a div and show the background as it is behind the div... I would not have thought this to be possible, but you SO pros continue to surprise me here so I thought it was worth a shot :-)
This is what I would like to achieve (sorry for the faint image):
Please do not answer this question with a 3 column solution or something similar, I am more than capable of achieving this that way... I simply want to know if there are any cool CSS tricks out there that can achieve this with as a few graphics, if not no graphics, as possible?

It is possible to fake it, with some fantasy and some little tricks:
Use border-radius to cut out a transparent corner of the div;
Use ::before (or ::after) pseudo element to create a big triangle of the same background-color of the div;
Use z-index to put the triangle over the background div but under the content of the div;
Use a transparent container with the same size of your div to contain it, and apply overflow: hidden to cut the exceeding parts of the triangle;
et voilĂ !
Demo: http://jsfiddle.net/e2Umv/
And no, I didn't know it was possible, I just love challenges and tricky questions :)
HTML
<div class="someText" >
this text is partially visible;<br/>
this text is partially visible;<br/>
this text is partially visible;<br/>
this text is partially visible;<br/>
this text is partially visible;<br/>
</div>
<div class="underneathContainer">
<div class="cutout">Hello cut out div</div>
</div>
CSS
.someText{
background: green;
position: absolute;
z-index: 0;
top: 0;
}
.underneathContainer{
margin: 20px;
width: 260px;
height: 260px;
background: rgba(0,0,0,0);
overflow: hidden;
}
.cutout{
width: 200px;
height: 200px;
background: silver;
padding: 30px;
position: relative;
z-index: 1;
border-top-left-radius:30%;
}
.cutout:before{
content: '';
position: absolute;
top: -44px;
left: -30px;
border-width: 60px 60px 60px 60px;
border-style: solid;
border-color: rgba(0,0,0,0) silver silver rgba(0,0,0,0);
z-index: -1;
}

You could seperate your triangle from the rectangle and go with something like this:
<div id="rectangle"><div id="mask"></div></div>
#rectangle{width:300px; height:120px; position:relative; margin-top:100px; background: rgb(30,87,153); /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzFlNTc5OSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiM3ZGI5ZTgiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(top, rgba(30,87,153,1) 0%, rgba(125,185,232,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(30,87,153,1)), color-stop(100%,rgba(125,185,232,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(30,87,153,1) 0%,rgba(125,185,232,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(30,87,153,1) 0%,rgba(125,185,232,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(30,87,153,1) 0%,rgba(125,185,232,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(30,87,153,1) 0%,rgba(125,185,232,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 ); /* IE6-8 */
}
#rectangle:after{content:" "; position:absolute; width:0px; height:0px; top:0; left:100px;border:1px solid white; border-color:transparent white transparent white; border-width:0px 50px 50px 50px;}
#mask{position:absolute; left:0; width:100px; height:50px; background:white;}
#mask:after{position:absolute; content:" "; left:200px; width:100px; background:white; height:50px; }
Fiddle here.

The only thing I can think of that applies here would be the image mask. You'd probably have to lay an element on top of another to have content over the mask.
The support for image-masks is not ubiquitous (only webkit at present I believe) but that will probably change over time.

Related

Multiple color background HTML

I'm trying to create a multiple color background to implement this:
And right now I managed to do this:
What I did:
Desired Background:
I'm trying to do it using gradients, but it seems that it's not possible to combine two gradients to do that. (It's possible to do other things, but not this).
Is there a way to implement this backgorund?
Thanks!
Try this (adjust the percentage and colors as your needs):
.yourdiv{
background: #ffffff;
background: -moz-linear-gradient(top, #ffffff 0%, #ffffff 70%, #f1f1f1 70%, #f1f1f1 100%);
background: -webkit-linear-gradient(top, #ffffff 0%,#ffffff 70%,#f1f1f1 70%,#f1f1f1 100%);
background: linear-gradient(to bottom, #ffffff 0%,#ffffff 70%,#f1f1f1 70%,#f1f1f1 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#f1f1f1',GradientType=0 );
}
DEMO HERE
i am guessing u need the darker grey section in the desired output to be shown? if so i would suggest to divide it into sections and give individual background.
if u can post some code. i would be happy to help.
Okay, not sure if this is exactly what you want but this is how I'd do psd to css/html. See screen shot below.
Also a WORKING DEMO HERE
Just wrap the whole card in a div and apply a left border would do the trick.
border-left-width: 8px;
border-left-color: rgba(10, 255, 80, 0.75);
border-radius: 5px;
You may remove the box shadow if you don't want, just feel move active with it.
At the end, I managed to do it with this:
This for the GREEN part:
.assignment-item {
padding: 5px 5px 0px 10px !important;
margin:15px auto;
border-radius: 8px;
background: linear-gradient(to right, #4f8b2b 0%,#4f8b2b 2%,#ffffff 2%,#ffffff 100%, transparent) !important;
}
This for the GREY part:
.assignment-item:before{
position:absolute;
z-index:-1;
bottom:0;
left:2%;
width:100%;
height:25%;
content:"";
background-color:#f2f2f2;
}
Here is the result:

CSS Gradient Overlay Click-Through Issue

I'm using this jQuery library to help stream a bunch of logos: SmoothDivScroll
Got it working great and I love it.
But I wanted to add just one more thing. I want a gradient overlay over the scroller so that on each side of the scroller the logos transition from white -> opaque -> white by the time it scrolls to the other side.
Something similar to this site: http://creativehero.es/
I got it working with the following code EXCEPT it kills my hyperlinks for each logo. I've tried messing around with pointer-events/z-index and I just can't get the overlay on top of the scroller and also have the logos in the scroller clickable. It's also always the same behavior across all modern browsers. Here's the CSS:
/* The scroll wrapper is always the same width and height as the containing element (div).
Overflow is hidden because you don't want to show all of the scrollable area.
*/
div.scrollWrapper
{
position: relative;
overflow: hidden;
width: 100%;
height: 100%;
z-index:-1;
pointer-events: visible;
}
div.scrollableArea
{
position: relative;
width: auto;
height: 100%;
pointer-events: visible;
}
#logoParade
{
width: auto;
height: 80px;
position: relative;
pointer-events: visible;
}
#logoParade a
{
display: block;
float: left;
margin-left: 15px;
margin-right: 15px;
margin-top: 8px;
margin-bottom: 8px;
pointer-events: visible;
z-index:210;
}
#logoParade img
{
height:65px;
width:auto;
pointer-events: visible;
}
#logoParade img:hover {
-ms-transform: scale(1.03,1.03); /* IE 9 */
-webkit-transform: scale(1.03,1.03); /* Chrome, Safari, Opera */
transform: scale(1.03,1.03);
}
.grad {
pointer-events: none;
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIxJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjIwJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIwIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjUwJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIwIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjgwJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIwIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNmZmZmZmYiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(left, rgba(255,255,255,1) 1%, rgba(255,255,255,0) 20%, rgba(255,255,255,0) 50%, rgba(255,255,255,0) 80%, rgba(255,255,255,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(1%,rgba(255,255,255,1)), color-stop(20%,rgba(255,255,255,0)), color-stop(50%,rgba(255,255,255,0)), color-stop(80%,rgba(255,255,255,0)), color-stop(100%,rgba(255,255,255,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgba(255,255,255,1) 1%,rgba(255,255,255,0) 20%,rgba(255,255,255,0) 50%,rgba(255,255,255,0) 80%,rgba(255,255,255,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgba(255,255,255,1) 1%,rgba(255,255,255,0) 20%,rgba(255,255,255,0) 50%,rgba(255,255,255,0) 80%,rgba(255,255,255,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, rgba(255,255,255,1) 1%,rgba(255,255,255,0) 20%,rgba(255,255,255,0) 50%,rgba(255,255,255,0) 80%,rgba(255,255,255,1) 100%); /* IE10+ */
background: linear-gradient(to right, rgba(255,255,255,1) 1%,rgba(255,255,255,0) 20%,rgba(255,255,255,0) 50%,rgba(255,255,255,0) 80%,rgba(255,255,255,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#ffffff',GradientType=1 ); /* IE6-8 */
}
And here's the html:
<div class="row grad" >
<div id="logoParade">
<div class="scrollWrapper">
<div class="scrollableArea" style="width: 6000px;">
#inherits umbraco.MacroEngines.DynamicNodeContext
#*
Macro Parameters To Create, for this macro to work:
Show:True Alias:mediaId Name:Media Folder ID Type:MediaCurrent
*#
#if (Parameter.mediaId == null)
{
#* Get the media folder as a dynamic node *#
var mediaFolder = Library.MediaById(5093);
if (mediaFolder.Children.Any())
{
#* for each item in children of the selected media folder *#
foreach (var mediaItem in mediaFolder.Children)
{
<img src="#mediaItem.umbracoFile" alt="#mediaItem.Name" />
}
}
}
</div>
</div>
</div>
</div>
I also want to add that adding z-index:-1 to either div element (scrollWrapper or scrollableArea) brings the gradient out in front of the scroller, but that is also the culprit not allowing my anchor tags to be clicked.

CSS gradient over another element. Is that possible?

I'm interested in technique, that allows to make such gradients OVER another div (white fading horizontal line). This is what I want it look like:
And this is what I have at the moment (yeah, I know):
Horizontal line is a simple with color css property,
Gradient is:
pointer-events: none;
height: 457px;
position: absolute;
right: 0;
top: -80px;
width: 100%;
background: radial-gradient(circle at center, rgba(255,255,255,0.15) 0%,rgba(255,255,255,0) 20%);
Image is a simple (rails image_tag) with absolute positioning.
Here is a hint. You can create multiple shapes of triangle with CSS and you have to just position and rotate the shapes to match your logo.
For instance, below is an example of one shape. You can take references of it and replicate it and make it the way you want. Here you go.
The HTML:
<div class="shape"></div>
The CSS:
.shape{
height: 100px;
width: 100px;
position:relative;
background: rgb(xxx,xxx,xxx);
background: -moz-linear-gradient(top, rgba(xxx,xxx,xxx,xxx) xxx%, rgba(xxx,xxx,xxx,xxx) xxx%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(xxx%,rgba(xxx,xxx,xxx,x)), color-stop(xxx%,rgba(xxx,xxx,xxx,x)));
-webkit-linear-gradient(top, rgba(xxx,xxx,xxx,x) xxx%,rgba(xxx,xxx,xxx,x) xxx%);
-o-linear-gradient(top, rgba(xxx,xxx,xxx,x) xx%,rgba(xxx,xxx,xxx,x) xxx%);
-ms-linear-gradient(top, rgba(xxx,xxx,xxx,x) 0%,rgba(xxx,xxx,xxx,x) xxx%);
linear-gradient(top, rgba(xxx,xxx,xxx,x) 0%,rgba(xxx,xxx,xxx,x) xxx%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#xxx', endColorstr='#xxx',GradientType=0 );
}
.shape:after {
-moz-transform: rotate(xxdeg);
-ms-transform:rotate(xxdeg);
-webkit-transform:rotate(xxdeg);
-o-transform:rotate(xxdeg);
background: none repeat 0 0 xxx;
content: "";
height: xxx;
left: xxx;
position: absolute;
top: xxx;
width: xxx;
}
The "xx" or "x" or "xxx" are dummy values which you can replace it with yours.
Hope this helps.

CSS button with slanted bottom right corner

I'm trying to achieve a rectangle button with a transparent mask over the bottom right, as per this fiddle:
http://jsfiddle.net/c6gUX/
body {
background: #fff;
padding: 5em;
}
.button {
color: #FFFFFF;
font-family: 'RalewayRegular', Arial,sans-serif;
font-size: 1em;
padding: 0.5em 1.2em 0.5em 0.8em;
position: relative;
text-decoration: none;
}
.button:hover {
background: linear-gradient(to bottom, #FFA13E 0px, #E56204 100%) repeat scroll 0 0 transparent;
color: #FFFFFF;
}
.button:after {
background: url(http://i.imgur.com/8Vvw1Sw.png) no-repeat scroll 0 0 transparent;
bottom: -12px;
content: " ";
height: 38px;
position: absolute;
right: -12px;
width: 36px;
z-index: 99;
}
.orange-grad {
background: #ffa13e; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2ZmYTEzZSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNmZjc4MDUiIHN0b3Atb3BhY2l0eT0iMSIvPgogICAgPHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjZmY3ODA1IiBzdG9wLW9wYWNpdHk9IjEiLz4KICA8L2xpbmVhckdyYWRpZW50PgogIDxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIGZpbGw9InVybCgjZ3JhZC11Y2dnLWdlbmVyYXRlZCkiIC8+Cjwvc3ZnPg==);
background: -moz-linear-gradient(top, #ffa13e 0%, #ff7805 100%, #ff7805 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffa13e), color-stop(100%,#ff7805), color-stop(100%,#ff7805)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #ffa13e 0%,#ff7805 100%,#ff7805 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #ffa13e 0%,#ff7805 100%,#ff7805 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #ffa13e 0%,#ff7805 100%,#ff7805 100%); /* IE10+ */
background: linear-gradient(to bottom, #ffa13e 0%,#ff7805 100%,#ff7805 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffa13e', endColorstr='#ff7805',GradientType=0 ); /* IE6-8 */
}
As you can see, i've achieved it with a quite hacky way. I've untested this cross-browser and suspect IE to mess it up without a shim for :after, etc.
How can I achieve this cross-browser modern? How can I make it work when overlayed onto an image so it's effectively transparent? (See below image)
From PSD:
My fiddle on an image:
Logically I know that IE6/7 will need an image and i'm kinda OK with that.
Word length. Sometimes the button doesn't have 'Read more', so need a 100% width solution.
Edit
I am thinking of using a Sprite. (http://i.imgur.com/z0UYpTX.png)
This is tricky - particularly with your combination of a gradient with the beveled corner. The closest I could get is this fiddle, which makes use of CSS gradients to achieve the effect you're after, based on Lea Verou's awesome article.
The relevant CSS is:
.button {
background: #ffa13e; /* fallback */
background: -webkit-linear-gradient(135deg, transparent 10px, #ff7805 10px, #ffa13e 100%);
background: -moz-linear-gradient(135deg, transparent 10px, #ff7805 10px, #ffa13e 100%);
background: -o-linear-gradient(135deg, transparent 10px, #ff7805 10px, #ffa13e 100%);
background: linear-gradient(315deg, transparent 10px, #ff7805 10px, #ffa13e 100%);
}
That's the only way to get the background image to show through (that I know of). The drawback is that the gradient is not your linear one from top to bottom, but at an angle. I don't think it's possible to combine multiple gradients to match your visual precisely. But it is pretty close:
I'd suggest that this is the perfect candidate for progressive enhancement - older IE will get a solid background colour but that's perfectly acceptable (i.e. I wouldn't personally bother trying for an image fallback).
Note: there have been numerous changes between the Working Draft and the Candidate Recommendation for the gradient syntax, one of which is the angle of the gradient:
From the IE Blog. Hence the unprefixed version requires a different deg value.
Make use of it..... I think this will help You.. use it with ur image.. this will solve cross-browser issue...
http://jsfiddle.net/Praveen16oct90/2bZAW/1095/
div {
width:200px;
height:80px;
background: red;
top:150px;left:100px;
position: relative;
}
div:before {
content: '';
position: absolute;
top: 40px; right: 0;
border-right: 40px solid white;
border-top: 40px solid red;
width: 20;
}

How do I stop my :after content from blocking my anchor?

I've made a simple Fiddle to demonstrate my problem. http://jsfiddle.net/JTqww/
HTML:
<body>
<div class="button">
<a href="#">
<img SRC="http://www.mikesfreegifs.com/main4/halloween/comehere.gif"/>
<span class="desc">Description</span>
</a>
</div>
</body>
CSS:
.button {
float: left;
width: 100px;
}
.button a {
background:green;
float:left;
z-index:-1;
}
img {
display:inline-block;
}
.desc{
display:inline-block;
text-align:center;
width:200px;
background-color:blue;
color:white;
}
.button:after {
position: absolute;
top: 10%;
left: 10%;
content:"I destroy your anchor";
color:red;
position: absolute;
width: 50%;
height: 50%;
background: -moz-linear-gradient(top, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,1)), color-stop(100%,rgba(255,255,255,0))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#00ffffff',GradientType=0 ); /* IE6-9 */
}
As you can see, I've made a button with an overlaid glass reflection effect, on top of an image. I wanted the image and the description below to all be wrapped in an anchor tag (which they are but the :after content seems to block the anchor). If you move the mouse outside of the glossy white area, it will interact with the anchor but inside that area of white gloss it will not.
I've tried floating the anchor and changing the z-index but the content placed :after the button (the 'gloss') seems to stop the anchor from receiving mouse-overs and click events.
Anyone know how to fix this? Any help much appreciated.
I workaround with your code, so that it looks nice.
Here is the fiddle
To make the click work on the added description too, just give :after to a or span tag instead of the class .button.
Working Fiddle
As your :after content is not part of the anchor it won't be clickable so you cannot place it over the top of your anchor and then expect to be able to click your anchor
now if you changed .before:after to .desc:after your link will be clickable:
http://jsfiddle.net/JTqww/2/
you'll just have to mess with the styles to get it to line up again
Instead you can give direct div
<div class="button">
<a href="#">
<img src="http://www.mikesfreegifs.com/main4/halloween/comehere.gif"/>
<div class="overlay">I destroy your anchor</div>
<span class="desc">Description</span>
</a>
</div>
DEMO
As #Pete states, your generated content is not part of your anchor, so it won't act as such. The simplest fix is just to remove your div.button altogether, and apply that class directly to your a:
<a href="#" class="button">
<img SRC="http://www.mikesfreegifs.com/main4/halloween/comehere.gif"/>
<span class="desc">Description</span>
</a>
The generated content itself is part of the anchor and so is clickable. Your initial CSS needs some tidying up as well. The button class, whatever it's applied to, needs to have position: relative so that it creates a new positioning context. The overlay will then sit correctly - see this fork.