I'm building a wizard-like ordering process where I have this menu:
The active page is colored green (in this case, Model).
How does one make this arrow using only CSS?:
At the moment i'm achieving my goal by using several divs and images:
<div class="menuItem">
<div></div> <!-- The left image -->
<div>Varianten</div>
<div></div> <!-- The right image -->
</div>
The left image:
The right image:
I found a SO answer which does part of this: Arrow Box with CSS, however i'm having trouble with the indent at the left.
If you have a better idea about how to do this, please let me know!
Here is an alternate approach to the whole thing using CSS3 features. One advantage of using this method (and one of the main reasons for adding a separate answer) is that the space in between the arrows can be transparent.
Basically the implementation is as follows:
div
for each step/item and it contains the text that needs to be displayed. Let us say theheight
of thisdiv
isx
(50px in this example).:before
and:after
) are created with theirwidth
the same as the parentdiv
andheight
as half (x/2
) of the parent. The:before
element has noborder-bottom
whereas the:after
element has noborder-top
to avoid a line appearing in the middle of the shape (parallel to x-axis).skew
transformed in opposite directions and are positioned in such a way that they are directly below each other and thus ends up forming the required shape.z-index
to push them to be behind the parentdiv
(and therefore its text).first-child
and thelast-child
elements are modified slightly (left
position,border
of pseudo-elements,background
andborder
of parentdiv
) to achieve the straight sides.active
class for active elements andhover
effects also to the shapes like in the below sample.Screenshot: (with the hover on second item)
Responsive Implementation with Transparent Background:
For a responsive version of the progress tracker bar with semi-transparent boxes, visit this pen. The width of each step/item is assigned in such a way that their sum is always 100% of the available width and each itemis always of the same size as the others.
JavaScript is used for the following features: (All these features are value-add and can be removed depending on the needs. Note that when the JS is removed, the corresponding CSS properties should be put into the CSS file.)
Here's some great arrows for you
SOURCE
Note
this also allows gradient backgrounds/etc
For other shapes, I saw this codepen the other day, too
If the space between the arrows does not need to be transparent (it is solid color) you can use the
:before
and:after
to create the edges (without new elements in DOM)Basically, it creates rotated squares with the borders we want and places them accordingly
If you want transparent spaces between tabs, Harry's current answer is they way to go.
But if you want to remove hover issues, you can try the following. It uses
box-shadow
for pseudo-elements instead of background with solid colour.The same effect is achievable using
border: _px inset #___ ;
FIDDLE
Final version
You can hover it seamlessly. It includes flat edges of first and last tabs.
FIDDLE (final)
Output: