I would like to make a transparent arrow over an image. This triangle should be indented in a semi transparent block and show the background image.
Desired output:
.barShow {
background-color: #000;
opacity: 0.5;
}
.barShow:before {
top: 0%;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-top-color: #999;
border-width: 20px;
margin-left: -20px;
}
<div class="barShow"></div>
The transparent CSS Arrow should be transparent without color.
Here is a solution using CSS clip-path that doesn't overflow the wrapper.
Simple Approach
Use pseudo element with
box-shadow
andtransform: rotate();
Add
overflow: hidden;
to main div.Snippet :
There are several approaches to make a transparent arrow over an image with CSS. The two I will describe involve pseudo elements to minimize markup and have the same output. You can also see an SVG approach at the end of this answer :
The transparent effect on the black part arround the arrow is made with
rgba()
colors that allow transparency. But you can use opacity on the pseudo elements if you prefer.1. SkewX()
You can use the CSS3
skewX()
property on two pseudo elements to make the transparent arrow. The main asset of this approach is that the transparent arrow can be responsive but it also allows you to put a border on the black shape and around the traingle.The responsiveness of the shape is made with the
padding-bottom
property to maintain it's aspect ratio (this technique is described here).DEMO
Browser support for the
transform : skew()
property is IE9+ (see canIuse).2. Border
The asset of this technique is browser support so if you need IE8 support this one is for you. The drawback is that the shape can't be responsive because border can't use % widths.
DEMO
3. Play with it!
Example : if you can change the black transparent color to the same as your background color (white here), you can make an transparent triangle/arrow with the same background image as the block :
DEMO
4. Tooltip with a triangle over an image.
If you need to use this shape over another image, background gradient or whatever non plain color, you will need to use a different approach in order to see the image all around the shape like this:
The point is to use the same image twice. Once in the div element and once in the triangle and to postion them exactly at the same place with absolute positioning. The arrow is made with
transform:rotate();
.DEMO
DEMO with box shadows.
5. SVG and cliPath
DEMO using an svg tag and clipPath.
This might be a semanticaly better approach if you are making graphics.