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!
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
#flowBoxes {
margin:auto;
padding:20px;
min-width:700px;
}
#flowBoxes div {
display:inline-block;
position:relative;
height:25px;
line-height:25px;
padding:0 20px;
border:1px solid #ccc;
margin-right:2px;
background-color:white;
}
#flowBoxes div.right:after{
content:'';
border-top:1px solid #ccc;
border-right:1px solid #ccc;
width:18px;
height:18px;
position:absolute;
right:0;
top:-1px;
background-color:white;
z-index:150;
-webkit-transform: translate(10px,4px) rotate(45deg);
-moz-transform: translate(10px,4px) rotate(45deg);
-ms-transform: translate(10px,4px) rotate(45deg);
-o-transform: translate(10px,4px) rotate(20deg);
transform: translate(10px,4px) rotate(45deg);
}
#flowBoxes div.left:before{
content:'';
border-top:1px solid #ccc;
border-right:1px solid #ccc;
width:18px;
height:18px;
position:absolute;
left:0;
top:-1px;
background-color:white;
z-index:50;
-webkit-transform: translate(-10px,4px) rotate(45deg);
-moz-transform: translate(-10px,4px) rotate(45deg);
-ms-transform: translate(-10px,4px) rotate(45deg);
-o-transform: translate(-10px,4px) rotate(20deg);
transform: translate(-10px,4px) rotate(45deg);
}
#flowBoxes .active{
background-color:green;
color:white;
}
#flowBoxes div.active:after{
background-color:green;
}
<div id="flowBoxes">
<div class="right">Diersoort / I&R</div>
<div class="left right active">Model</div>
<div class="left right">Varianten</div>
<div class="left right">Bedrukkingen</div>
<div class="left">Bevestiging</div>
</div>
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:
There is one div for each step/item and it contains the text that needs to be displayed. Let us say the height of this div is x (50px in this example).
Two pseudo-elements (:before and :after) are created with their width the same as the parent div and height as half (x/2) of the parent. The :before element has no border-bottom whereas the :after element has no border-top to avoid a line appearing in the middle of the shape (parallel to x-axis).
These two pseudo-elements are then 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.
The pseudo-elements are assigned a negative z-index to push them to be behind the parent div (and therefore its text).
The first-child and the last-child elements are modified slightly (left position, border of pseudo-elements, background and border of parent div) to achieve the straight sides.
We can add an active class for active elements and hover effects also to the shapes like in the below sample.
.steps {
height: 50px;
width: 150px;
text-align: center;
line-height: 50px;
position: relative;
margin: 10px 0px 10px 20px;
display: inline-block;
}
.steps:before,
.steps:after {
content: '';
position: absolute;
left: 0px;
width: 150px;
height: 25px;
z-index: -1;
}
.steps:before {
top: -2px;
border-top: 2px solid blue;
border-right: 2px solid blue;
border-left: 2px solid blue;
background: lightblue;
-moz-transform: skew(30deg);
-webkit-transform: skew(30deg);
transform: skew(30deg);
}
.steps:after {
bottom: -2px;
border-left: 2px solid blue;
border-right: 2px solid blue;
border-bottom: 2px solid blue;
background: lightblue;
-moz-transform: skew(-30deg);
-webkit-transform: skew(-30deg);
transform: skew(-30deg);
}
.steps:last-child {
background: lightblue;
border-right: 2px solid blue;
border-top: 2px solid blue;
border-bottom: 2px solid blue;
margin-left: 38px;
}
.steps:first-child {
background: lightblue;
border-left: 2px solid blue;
border-top: 2px solid blue;
border-bottom: 2px solid blue;
margin-right: 18px;
}
.steps:first-child:before,
.steps:first-child:after {
left: 18px;
}
.steps:last-child:before,
.steps:last-child:after {
left: -18px;
}
/* Hover Styles */
.steps:first-child:hover,
.steps:last-child:hover,
.steps:hover:before,
.steps:hover:after {
background: lightgreen;
}
.steps:first-child:hover {
border-left: 2px solid green;
}
.steps:last-child:hover {
border-right: 2px solid green;
}
.steps:hover:before {
border-top: 2px solid green;
border-right: 2px solid green;
border-left: 2px solid green;
}
.steps:hover:after {
border-left: 2px solid green;
border-right: 2px solid green;
border-bottom: 2px solid green;
}
.steps:first-child:hover,
.steps:last-child:hover {
border-top: 2px solid green;
border-bottom: 2px solid green;
}
/* Active Styles */
.active:first-child,
.active:last-child,
.active:before,
.active:after{
background: bisque;
}
.active:first-child{
border-left: 2px solid red;
}
.active:last-child{
border-right: 2px solid red;
}
.active:before{
border-top: 2px solid red;
border-right: 2px solid red;
border-left: 2px solid red;
}
.active:after{
border-left: 2px solid red;
border-right: 2px solid red;
border-bottom: 2px solid red;
}
.active:first-child, .active:last-child{
border-top: 2px solid red;
border-bottom: 2px solid red;
}
/* Just for creating a non solid color background */
body{
height: 200px;
background: -webkit-radial-gradient(center, ellipse, #400, #100);
background: -moz-radial-gradient(center, ellipse, #400, #100);
background: radial-gradient(center, ellipse, #400, #100);
}
<div class='steps-container'>
<div class='steps'>1. Step 1</div>
<div class='steps active'>2. Step 2</div>
<div class='steps'>3. Step 3</div>
</div>
Note: The hover in the above snippet doesn't work when hovering on the right tip of the first-child or the left tip of the last-child because of z-index issues. If you need seamless hover functionality then using a span inside the .steps element like in the below snippet would solve it. (Thanks to The Pragmatick for pointing this out).
.steps {
height: 50px;
width: 150px;
text-align: center;
line-height: 50px;
position: relative;
margin: 10px 0px 10px 20px;
display: inline-block;
}
.steps span {
position: relative;
z-index: 2;
}
.steps:before,
.steps:after {
content: '';
position: absolute;
left: 0px;
width: 150px;
height: 25px;
}
.steps:before {
top: -2px;
border-top: 2px solid blue;
border-right: 2px solid blue;
border-left: 2px solid blue;
background: lightblue;
-moz-transform: skew(30deg);
-webkit-transform: skew(30deg);
transform: skew(30deg);
}
.steps:after {
bottom: -2px;
border-left: 2px solid blue;
border-right: 2px solid blue;
border-bottom: 2px solid blue;
background: lightblue;
-moz-transform: skew(-30deg);
-webkit-transform: skew(-30deg);
transform: skew(-30deg);
}
.steps:first-child:before,
.steps:first-child:after {
border-left: none;
}
.steps:last-child:before,
.steps:last-child:after {
border-right: none;
}
.steps:last-child {
background: lightblue;
border-right: 2px solid blue;
border-top: 2px solid blue;
border-bottom: 2px solid blue;
margin-left: 38px;
}
.steps:first-child {
background: lightblue;
border-left: 2px solid blue;
border-top: 2px solid blue;
border-bottom: 2px solid blue;
margin-right: 18px;
}
.steps:first-child:before,
.steps:first-child:after {
left: 18px;
}
.steps:last-child:before,
.steps:last-child:after {
left: -18px;
}
/* Hover Styles */
.steps:first-child:hover,
.steps:last-child:hover,
.steps:hover:before,
.steps:hover:after {
background: lightgreen;
}
.steps:first-child:hover {
border-left: 2px solid green;
}
.steps:last-child:hover {
border-right: 2px solid green;
}
.steps:hover:before {
border-top: 2px solid green;
border-right: 2px solid green;
border-left: 2px solid green;
}
.steps:hover:after {
border-left: 2px solid green;
border-right: 2px solid green;
border-bottom: 2px solid green;
}
.steps:first-child:hover,
.steps:last-child:hover {
border-top: 2px solid green;
border-bottom: 2px solid green;
}
.steps:first-child:hover:before,
.steps:first-child:hover:after {
border-left: none;
}
.steps:last-child:hover:before,
.steps:last-child:hover:after {
border-right: none;
}
/* Active Styles */
.active:first-child,
.active:last-child,
.active:before,
.active:after {
background: bisque;
}
.active:first-child {
border-left: 2px solid red;
}
.active:last-child {
border-right: 2px solid red;
}
.active:before {
border-top: 2px solid red;
border-right: 2px solid red;
border-left: 2px solid red;
}
.active:after {
border-left: 2px solid red;
border-right: 2px solid red;
border-bottom: 2px solid red;
}
.active:first-child,
.active:last-child {
border-top: 2px solid red;
border-bottom: 2px solid red;
}
/* Just for creating a non solid color background */
body {
height: 200px;
background: -webkit-radial-gradient(center, ellipse, #400, #100);
background: -moz-radial-gradient(center, ellipse, #400, #100);
background: radial-gradient(center, ellipse, #400, #100);
}
<div class='steps-container'>
<div class='steps'>
<span>1. Step 1</span>
</div>
<div class='steps active'>
<span>2. Step 2</span>
</div>
<div class='steps'>
<span>3. Step 3</span>
</div>
</div>
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.)
Automatically adjust the width of each item depending on the no. of items that are present in the bar
Automatically adjust the width of each item when the window is resized
Automatically adjust the appearance of the items when the height of the bar is increased or decreased by using the slider.
Here's some great arrows for you
html{
background-color:red;
}
div#page {
padding-bottom: 40px;
padding-top: 40px;
text-align: center;
z-index: 1;
position: relative;
}
div.diamond, div.ribbon, div.right-arrow, div.left-arrow {
display: inline-block;
color: #FFFFFF;
font-size: 22px;
line-height: 38px;
margin: 15px 0;
position: relative;
width: 200px;
}
div.diamond:before, div.diamond:after, div.ribbon:before, div.ribbon:after, div.right-arrow:before, div.right-arrow:after, div.left-arrow:before, div.left-arrow:after {
content:"";
border-style: solid;
border-width: 0;
height: 0;
position: absolute;
width: 0;
}
div.diamond {
background-color: #CCCCCC;
}
div.diamond:after, div.diamond:before {
border-color: transparent #CCCCCC;
}
div.diamond:before {
left: -19px;
border-width: 19px 19px 19px 0;
}
div.diamond:after {
right: -19px;
border-width: 19px 0 19px 19px;
}
div.ribbon {
background-color: #CCCCCC;
}
div.ribbon:before, div.ribbon:after {
top: 6px;
z-index: -15;
}
div.ribbon:before {
border-color: #B2B2B2 #B2B2B2 #B2B2B2 transparent;
border-width: 19px;
left: -25px;
}
div.ribbon:after {
border-color: #B2B2B2 transparent #B2B2B2 #B2B2B2;
border-width: 19px;
right: -25px;
}
div.right-arrow {
background-color: #CCCCCC;
}
div.right-arrow:after, div.right-arrow:before {
border-width: 19px 0 19px 19px;
}
div.right-arrow:before {
border-color: #CCCCCC transparent;
left: -19px;
}
div.right-arrow:after {
border-color: transparent #CCCCCC;
right: -19px;
}
div.left-arrow {
background-color: #CCCCCC;
}
div.left-arrow:after, div.left-arrow:before {
border-width: 19px 19px 19px 0;
}
div.left-arrow:before {
border-color: transparent #CCCCCC;
left: -19px;
}
div.left-arrow:after {
border-color: #CCCCCC transparent;
right: -19px;
}
<div id="page">
<div class="diamond">Diamond</div>
<br>
<div class="ribbon">Ribbon</div>
<br>
<div class="right-arrow">Right arrow</div>
<br>
<div class="left-arrow">Left arrow</div>
</div>
SOURCE
Note
this also allows gradient backgrounds/etc
For other shapes, I saw this codepen the other day, too
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 #___ ;
.li {
height: 50px;
width: 120px;
background: #F5FBF1;
display: inline-block;
position: relative;
margin-left: 30px;
line-height: 50px;
color: black;
font-family: sans-serif;
text-align: center;
}
.li:before, .li:after {
content: '';
left: -15px;
position: absolute;
height: 23px;
width: 132px;
border-left: 2px solid black;
border-right: 2px solid black;
}
.li:before {
border-top: 2px solid black;
-webkit-transform-origin: 0% 0%;
-moz-transform-origin: 0% 0%;
-ms-transform-origin: 0% 0%;
transform-origin: 0% 0%;
-webkit-transform: skewX(30deg);
-moz-transform: skewX(30deg);
-ms-transform: skewX(30deg);
transform: skewX(30deg);
top: 0;
box-shadow: inset 0 8px 0 8px #F5FBF1, inset -6px 8px 0 8px #F5FBF1;
}
.li:after {
border-bottom: 2px solid black;
-webkit-transform-origin: 0% 100%;
-moz-transform-origin: 0% 100%;
-ms-transform-origin: 0% 100%;
transform-origin: 0% 100%;
-webkit-transform: skewX(-30deg);
-moz-transform: skewX(-30deg);
-ms-transform: skewX(-30deg);
transform: skewX(-30deg);
bottom: 0;
box-shadow: inset 0 -8px 0 8px #F5FBF1, inset -6px -8px 0 8px #F5FBF1;
}
.li:hover {
background: #C0EBA4;
}
.li:hover:before {
box-shadow: inset 0 8px 0 8px #C0EBA4, inset -6px 8px 0 8px #C0EBA4;
}
.li:hover:after {
box-shadow: inset 0 -8px 0 8px #C0EBA4, inset -6px -8px 0 8px #C0EBA4;
}
<div class="li">ONE</div>
<div class="li">TWO</div>
<div class="li">THREE</div>
<div class="li">FOUR</div>
<div class="li">FIVE</div>
FIDDLE
Final version
You can hover it seamlessly. It includes flat edges of first and last tabs.
.li {
height: 50px;
width: 100px;
padding-left: 20px;
background: #F5FBF1;
display: inline-block;
position: relative;
margin-left: 20px;
line-height: 50px;
font-family: sans-serif;
font-size: 15px;
}
.li:before, .li:after {
content: '';
left: -15px;
position: absolute;
height: 23px;
width: 132px;
border-left: 2px solid black;
border-right: 2px solid black;
}
.li:before {
border-top: 2px solid black;
-webkit-transform-origin: 0% 0%;
-moz-transform-origin: 0% 0%;
-ms-transform-origin: 0% 0%;
transform-origin: 0% 0%;
-webkit-transform: skewX(30deg);
-moz-transform: skewX(30deg);
-ms-transform: skewX(30deg);
transform: skewX(30deg);
top: 0;
box-shadow: inset 0 8px 0 8px #F5FBF1, inset -6px 8px 0 8px #F5FBF1;
}
.li:after {
border-bottom: 2px solid black;
-webkit-transform-origin: 0% 100%;
-moz-transform-origin: 0% 100%;
-ms-transform-origin: 0% 100%;
transform-origin: 0% 100%;
-webkit-transform: skewX(-30deg);
-moz-transform: skewX(-30deg);
-ms-transform: skewX(-30deg);
transform: skewX(-30deg);
bottom: 0;
box-shadow: inset 0 -8px 0 8px #F5FBF1, inset -6px -8px 0 8px #F5FBF1;
}
.li:hover {
background: #C0EBA4;
}
.li:hover:before { box-shadow: inset 0 8px 0 8px #C0EBA4, inset -6px 8px 0 8px #C0EBA4;}
.li:hover:after { box-shadow: inset 0 -8px 0 8px #C0EBA4, inset -6px -8px 0 8px #C0EBA4;}
/*First and Last styles*/
.li:first-of-type {
left: -15px;
box-shadow: 15px 0 0 0 #F5FBF1;
border-left: 2px solid black;
}
.li:first-of-type:before, .li:first-of-type:after {
left: -1px;
width: 135px;
border-left: 0;
}
.li:first-of-type:hover {box-shadow: 15px 0 0 0 #C0EBA4;}
.li:last-of-type {
left: 0px;
width: 115px;
box-shadow: inset -2px 0 0 0 black, inset 0 -2px 0 0 black, inset 0 2px 0 0 black;
border: 0;
}
.li:last-of-type:before, .li:last-of-type:after {
left: -15px;
border-right: 0;
}
.li:last-of-type:hover {background: #C0EBA4;}
<div class="li">Tab one</div>
<div class="li">Tab two</div>
<div class="li">Tab three</div>
<div class="li">Tab four</div>
<div class="li">Tab five</div>
FIDDLE (final)
Output:
Update
See this repl for added top-down support.
Screenshot (top-down)
Initial answer
I set up a repl with an highly customizable example using CSS's clip-path.
See here.
Screenshot
<script>
let arrowWidth = 25;
let stepPaddingX = 25;
let stepPaddingY = 0;
let stepGap = 5;
let height = 50;
$: cssVariables = `--height: ${height}px;--step-gap: ${stepGap}px;--arrow-width: ${arrowWidth}px; --step-padding-x: ${stepPaddingX}px; --step-padding-y: ${stepPaddingY}px`;
let wrap = false;
let wrapWords = true;
let pillStyle = true;
let limitHeight = false;
let autoHeight = true;
const steps = ["Test", "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam", "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam", "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam", "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam"]
</script>
<div class="settings">
<div class="setting">
<label for="setting__height">Height</label>
<input id="setting__height" min="50" max="200" bind:value={height} type="range"/>
</div>
<div class="setting">
<label for="setting__limit-height">Limit height</label>
<input id="setting__limit-height" bind:checked={limitHeight} type="checkbox"/>
</div>
<div class="setting">
<label for="setting__auto-height">Auto-height</label>
<input id="setting__auto-height" bind:checked={autoHeight} type="checkbox"/>
</div>
<div class="setting">
<label for="setting__arrow-width">Arrow width</label>
<input id="setting__arrow-width" bind:value={arrowWidth} type="range"/>
</div>
<div class="setting">
<label for="setting__step-padding-y">Step Padding Y</label>
<input id="setting__step-padding-y" bind:value={stepPaddingY} type="range"/>
</div>
<div class="setting">
<label for="setting__step-padding-x">Step Padding X</label>
<input id="setting__step-padding-x" bind:value={stepPaddingX} type="range"/>
</div>
<div class="setting">
<label for="setting__step-gap">Step Gap</label>
<input id="setting__step-gap" bind:value={stepGap} type="range"/>
</div>
<div class="setting">
<label for="setting__wrap-steps">Wrap steps</label>
<input id="setting__wrap-steps" bind:checked={wrap} type="checkbox"/>
</div>
<div class="setting">
<label for="setting__wrap-words">Wrap words</label>
<input id="setting__wrap-words" bind:checked={wrapWords} type="checkbox"/>
</div>
<div class="setting">
<label for="setting__pill-style">Pill style</label>
<input id="setting__pill-style" bind:checked={pillStyle} type="checkbox"/>
</div>
</div>
<div class="steps" class:wrap class:pillStyle class:limitHeight class:autoHeight style={cssVariables}>
{#each steps as step}
<div class="step" class:wrapWords>
{step}
</div>
{/each}
</div>
<style>
:global(body){
--arrow-width: 25px;
--step-gap: 5px;
--step-padding-x: 10px;
--height: 50px;
}
.settings {
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
}
.setting {
display: flex;
align-items: center;
gap: 0.5rem;
border: 1px solid #333;
border-radius: 5px;
padding: 0.25rem;
width: max-content;
}
input {
margin: 0;
}
.steps.pillStyle .step:first-of-type {
border-top-left-radius: 99999px;
border-bottom-left-radius: 99999px;
}
.steps.pillStyle .step:last-of-type {
border-top-right-radius: 99999px;
border-bottom-right-radius: 99999px;
}
.steps {
display: flex;
gap: var(--step-gap);
overflow-x: scroll;
/*scrollbar-width: none;*/
padding: 1rem 0;
}
.steps.wrap {
flex-wrap: wrap;
}
.steps.limitHeight .step{
max-height: 50px;
}
.steps.autoHeight .step{
height: unset;
}
.step:not(.wrapWords) {
white-space: nowrap;
}
.step {
background: #756bea;
width: auto;
height: var(--height);
color: #fff;
transform-style: preserve-3d;
position: relative;
display: flex;
justify-content: center;
align-items: center;
padding: var(--step-padding-y) var(--step-padding-x);
box-sizing: border-box;
}
.step:hover{
background: #4b3fe4;
}
.step:first-child {
/*padding-right: var(--arrow-width);*/
/*padding-left: var(--step-padding-x);*/
}
.step:first-child::after {
content: "";
background: inherit;
position: absolute;
left: 100%;
width: var(--arrow-width);
height: 100%;
clip-path: polygon(calc(100% - var(--arrow-width)) 0%, 100% 50%, calc(100% - var(--arrow-width)) 100%, 0% 100%, 0% 0%);
}
.step:not(:is(:first-child, :last-child))::before{
content: "";
background: inherit;
position: absolute;
right: 100%;
width: var(--arrow-width);
height: 100%;
clip-path: polygon(100% 0%, 100% 100%, 0% 100%, var(--arrow-width) 50%, 0% 0%);
}
.step:not(:is(:first-child, :last-child))::after {
content: "";
background: inherit;
position: absolute;
left: 100%;
width: var(--arrow-width);
height: 100%;
clip-path: polygon(calc(100% - var(--arrow-width)) 0%, 100% 50%, calc(100% - var(--arrow-width)) 100%, 0% 100%, 0% 0%);
}
.step:not(:last-child) {
margin-right: var(--arrow-width);
padding-left: var(--step-padding-x);
}
.step:last-child {
padding-left: var(--step-padding-x);
padding-right: var(--step-padding-x);
}
.step:last-child::before {
content: "";
background: inherit;
position: absolute;
right: 100%;
width: var(--arrow-width);
height: 100%;
clip-path: polygon(100% 0, 100% 100%, 0% 100%, var(--arrow-width) 50%, 0% 0%);
}
</style>
If you want a border for the steps look at this repl
<script>
let wrap = false;
let wrapWords = true;
let pillStyle = true;
let limitHeight = false;
let autoHeight = true;
let lockBorderToGap = false;
let arrowWidth = 25;
let stepPaddingX = 25;
let stepPaddingY = 0;
let stepGap = 5;
let height = 50;
let stepBorderWidth = 5;
$: cssVariables = `--height: ${height}px;--step-gap: ${stepGap}px;--arrow-width: ${arrowWidth}px; --step-padding-x: ${stepPaddingX}px; --step-padding-y: ${stepPaddingY}px; --step-border-width: ${stepBorderWidth}px`;
const steps = ["Test", "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam", "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam", "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam", "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam"]
</script>
<div class="settings">
<div class="setting">
<label for="setting__height">Height</label>
<input id="setting__height" min="50" max="200" bind:value={height} type="range"/>
</div>
<div class="setting">
<label for="setting__limit-height">Limit height</label>
<input id="setting__limit-height" bind:checked={limitHeight} type="checkbox"/>
</div>
<div class="setting">
<label for="setting__auto-height">Auto-height</label>
<input id="setting__auto-height" bind:checked={autoHeight} type="checkbox"/>
</div>
<div class="setting">
<label for="setting__arrow-width">Arrow width</label>
<input id="setting__arrow-width" bind:value={arrowWidth} type="range"/>
</div>
<div class="setting">
<label for="setting__step-padding-y">Step Padding Y</label>
<input id="setting__step-padding-y" bind:value={stepPaddingY} type="range"/>
</div>
<div class="setting">
<label for="setting__step-padding-x">Step Padding X</label>
<input id="setting__step-padding-x" bind:value={stepPaddingX} type="range"/>
</div>
<div class="setting">
<label for="setting__step-gap">Step Gap</label>
<input id="setting__step-gap" bind:value={stepGap} type="range"/>
</div>
<div class="setting">
<label for="setting__lock-border">Lock border to gap</label>
<input id="setting__lock-border" bind:checked={lockBorderToGap} type="checkbox"/>
</div>
<div class="setting">
<label for="setting__wrap-steps">Wrap steps</label>
<input id="setting__wrap-steps" bind:checked={wrap} type="checkbox"/>
</div>
<div class="setting">
<label for="setting__wrap-words">Wrap words</label>
<input id="setting__wrap-words" bind:checked={wrapWords} type="checkbox"/>
</div>
<div class="setting">
<label for="setting__pill-style">Pill style</label>
<input id="setting__pill-style" bind:checked={pillStyle} type="checkbox"/>
</div>
</div>
<div id="example" style={cssVariables}>
<div class="steps-wrapper" class:lockBorderToGap>
<div class="steps" class:wrap class:pillStyle class:limitHeight class:autoHeight>
{#each steps as step}
<div class="step" class:wrapWords>
{step}
</div>
{/each}
</div>
</div>
</div>
<style>
:global(body){
--arrow-width: 25px;
--step-gap: 5px;
--step-padding-x: 10px;
--height: 50px;
--step-border-width: 5px;
}
.settings {
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
margin-bottom: 2rem;
}
.setting {
display: flex;
align-items: center;
gap: 0.5rem;
border: 1px solid #333;
border-radius: 5px;
padding: 0.25rem;
width: max-content;
}
input {
margin: 0;
}
.steps.pillStyle .step:first-of-type {
border-top-left-radius: 99999px;
border-bottom-left-radius: 99999px;
}
.steps.pillStyle .step:last-of-type {
border-top-right-radius: 99999px;
border-bottom-right-radius: 99999px;
}
.steps-wrapper {
/*padding: 0.5rem;*/
box-sizing: border-box;
background: black;
border-radius: 99999px;
overflow: hidden;
border: var(--step-border-width) solid transparent;
}
.steps-wrapper.lockBorderToGap {
border-width: var(--step-gap);
}
.steps {
display: flex;
gap: var(--step-gap);
overflow-x: scroll;
scrollbar-width: none;
/*padding: 1rem 0;*/
}
.steps.wrap {
flex-wrap: wrap;
}
.steps.limitHeight .step{
max-height: 50px;
}
.steps.autoHeight .step{
height: unset;
}
.step:not(.wrapWords) {
white-space: nowrap;
}
.step {
background: #756bea;
width: auto;
height: var(--height);
color: #fff;
transform-style: preserve-3d;
position: relative;
display: flex;
justify-content: center;
align-items: center;
padding: var(--step-padding-y) var(--step-padding-x);
box-sizing: border-box;
}
.step:hover{
background: #4b3fe4;
}
.step:first-child {
/*padding-right: var(--arrow-width);*/
/*padding-left: var(--step-padding-x);*/
}
.step:first-child::after {
content: "";
background: inherit;
position: absolute;
left: 100%;
width: var(--arrow-width);
height: 100%;
clip-path: polygon(calc(100% - var(--arrow-width)) 0%, 100% 50%, calc(100% - var(--arrow-width)) 100%, 0% 100%, 0% 0%);
}
.step:not(:is(:first-child, :last-child))::before{
content: "";
background: inherit;
position: absolute;
right: 100%;
width: var(--arrow-width);
height: 100%;
clip-path: polygon(100% 0%, 100% 100%, 0% 100%, var(--arrow-width) 50%, 0% 0%);
}
.step:not(:is(:first-child, :last-child))::after {
content: "";
background: inherit;
position: absolute;
left: 100%;
width: var(--arrow-width);
height: 100%;
clip-path: polygon(calc(100% - var(--arrow-width)) 0%, 100% 50%, calc(100% - var(--arrow-width)) 100%, 0% 100%, 0% 0%);
}
.step:not(:last-child) {
margin-right: var(--arrow-width);
padding-left: var(--step-padding-x);
}
.step:last-child {
padding-left: var(--step-padding-x);
padding-right: var(--step-padding-x);
}
.step:last-child::before {
content: "";
background: inherit;
position: absolute;
right: 100%;
width: var(--arrow-width);
height: 100%;
clip-path: polygon(100% 0, 100% 100%, 0% 100%, var(--arrow-width) 50%, 0% 0%);
}
</style>
Related
I am trying to draw a tip in CSS.
I have "middle success" so far, the only problem is that, depending on DIV width, the tip sometimes are not in the center position.
What I want:
My code so far:
.logo {
color: #000;
font-size: 1.4em;
text-align: center;
padding-top: 1.5em;
text-transform: uppercase;
position: relative;
}
.line {
height: 1px;
overflow: hidden;
background: #000;
}
.line.top,
.line.bottom {
width: 90%;
}
.line.top {
margin: 0 auto 4px;
}
.line.bottom {
margin: 4px auto 0;
}
.angle {
position: absolute;
top: 19px;
left: 46%; // I think my problem is here!
}
.angle .line.left,
.angle .line.right {
width: 20px;
}
.angle .line.left {
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
margin: 7px;
}
.angle .line.right {
-ms-transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
margin: -7px;
}
<div class="logo">
<div class="angle">
<div class="line left"></div>
<div class="line right"></div>
</div>
<div class="line top"></div>
MY TEXT
<div class="line bottom"></div>
</div>
How can I solve this?
I thought setting .angle width: 30px and margin: 0 auto, but it have position: absolute, so it is not possible.
Ps: LESS can be used.
No need of so many elements. Just use .logo element and its pseudo classes. and use letter-spacing css property to give space between the letters. (or use the exact font, if you know the name)
CSS
.logo {
color: #000;
font-size: 1.4em;
text-align: center;
height: 2em;
margin-top: 2em;
letter-spacing: 1em;
text-transform: uppercase;
line-height: 2em;
position: relative;
border-top: 1px solid #000;
border-bottom: 1px solid #000;
}
.logo::after, .logo::before {
content:"";
border-width: 20px;
border-style: solid;
position: absolute;
left: 50%;
bottom: 100%;
transform: translateX(-50%);
}
.logo::after {
border-width: 18px;
margin-bottom: 1px;
border-color: transparent transparent white transparent;
}
.logo::before {
border-color: transparent transparent black transparent;
}
Working Fiddle - using CSS
Working Fiddle - using SCSS
Nested Triangles!
.outer {
border: 40px solid transparent;
border-bottom: 40px solid black;
width: 0;
height: 0;
position: relative;
margin: 0 auto;
}
.inner {
border: 36px solid transparent;
border-bottom: 36px solid white;
width: 0;
height: 0;
position: absolute;
top: -32px;
left: -36px;
}
<div class="outer">
<div class="inner"></div>
</div>
You could just rotate a div and add a border to it. Then using z-indexing put it behind a div with just a top and bottom border holding your text. Might look something like this:
<!DOCTYPE html>
<html>
<head>
<style>
html{padding: 10px;}
.triangle {
width: 10%;
height: 10%;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
z-index: -1;
border-top: 1px solid black;
border-left: 1px solid black;
position: absolute;
top: 20px;
left: 45%;
}
.textBox {
height: 40px;
border-top: 1px solid black;
border-bottom: 1px solid black;
background: white;
z-index: 2;
text-align: center;
}
</style>
</head>
<body>
<div class="logo">
<div class="triangle"></div>
<div class="textBox">
MY TEXT
</div>
</div>
</body>
</html>
body{
margin-top:70px;
}
h2{
color:#fff;
text-align:center;
}
.arrow_box {
position: relative;
background: #88b7d5;
border: 4px solid #c2e1f5;
}
.arrow_box:after, .arrow_box:before {
bottom: 100%;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.arrow_box:after {
border-color: rgba(136, 183, 213, 0);
border-bottom-color: #88b7d5;
border-width: 30px;
margin-left: -30px;
}
.arrow_box:before {
border-color: rgba(194, 225, 245, 0);
border-bottom-color: #c2e1f5;
border-width: 36px;
margin-left: -36px;
}
See working demo here.
I have a little question.
I have div 200*200 px. I need effect:
- when user mouse hover on div: alpha 70% black picture
- show new button at middle of picture (or textual link) for example "Add to cart"
You can see my example here: http://jsfiddle.net/t8jPN
<div class="wrapper">
<div class="ribbon-wrapper-green"><div class="ribbon-green">NEW</div></div>
<img src="http://cdn.sheknows.com/articles/2011/05/summer-dresses4.jpg"></img>
</div>
.wrapper {
margin: 50px auto;
width: 200px;
height: 200px;
background: white;
border-radius: 2px;
-webkit-box-shadow: 0px 0px 8px rgba(0,0,0,0.3);
-moz-box-shadow: 0px 0px 8px rgba(0,0,0,0.3);
box-shadow: 0px 0px 8px rgba(0,0,0,0.3);
position: relative;
z-index: 90;
}
.ribbon-wrapper-green {
width: 85px;
height: 88px;
overflow: hidden;
position: absolute;
top: -3px;
right: -3px;
}
.ribbon-green {
font: bold 15px Sans-Serif;
color: #ffffff;
text-align: center;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
position: relative;
padding: 7px 0;
left: -5px;
top: 15px;
width: 120px;
background-color: #BFDC7A;
background-image: -webkit-gradient(linear, left top, left bottom, from(#BFDC7A), to(#8EBF45));
background-image: -webkit-linear-gradient(top, #BFDC7A, #8EBF45);
background-image: -moz-linear-gradient(top, #BFDC7A, #8EBF45);
background-image: -ms-linear-gradient(top, #BFDC7A, #8EBF45);
background-image: -o-linear-gradient(top, #BFDC7A, #8EBF45);
color: #6a6340;
-webkit-box-shadow: 0px 0px 3px rgba(0,0,0,0.3);
-moz-box-shadow: 0px 0px 3px rgba(0,0,0,0.3);
box-shadow: 0px 0px 3px rgba(0,0,0,0.3);
}
.ribbon-green:before, .ribbon-green:after {
content: "";
border-top: 3px solid #6e8900;
border-left: 3px solid transparent;
border-right: 3px solid transparent;
position:absolute;
bottom: -3px;
}
.ribbon-green:before {
left: 0;
}
.ribbon-green:after {
right: 0;
}
Thanks
The basic idea is have wrapper for three divs. One div with the image, one div with the shadow and other for the button.
The reason there are separate divs for the shadow and the button (or link) is to avoid the transparency effect on the button.
I guess there are better ways to solve the problem but i would use this one because i find it easier.
Demo http://jsfiddle.net/chepe263/a97FS/10/
<html>
<head>
<style type="text/css">
.contenedor{
position:relative;
width: 200px;
height: 200px;
border: 1px solid black;
}
.atCorner{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.escondido{
display: none;
}
.shadow{
background-color: black;
zoom: 1;
filter: alpha(opacity=70);
opacity: 0.7;
}
.button{
text-align: center;
}
.button button{
margin-top: 40%;
}
</style>
<script type="text/javascript">
$('.contenedor').mouseenter(function(){
jQuery(this).find('.shadow, .button').fadeIn();
}).mouseleave(function(){
jQuery(this).find('.shadow, .button').fadeOut();
});
</script>
</head>
<body>
<div class="contenedor">
<div class="atCorner" id="picture">
<img src="http://cdn.sheknows.com/articles/2011/05/summer-dresses4.jpg" />
</div>
<div class="atCorner escondido shadow" id="">
</div>
<div class="atCorner escondido button" id="">
<button>Buy it</button>
</div>
</div>
</body>
</html>
from this:
http://www.kylejlarson.com/blog/2011/how-to-create-pie-charts-with-css3/
.pieContainer {
height: 100px;
}
.pieBackground {
background-color: grey;
position: absolute;
width: 100px;
height: 100px;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
-o-border-radius: 50px;
border-radius: 50px;
-moz-box-shadow: -1px 1px 3px #000;
-webkit-box-shadow: -1px 1px 3px #000;
-o-box-shadow: -1px 1px 3px #000;
box-shadow: -1px 1px 3px #000;
}
.pie {
position: absolute;
width: 100px;
height: 100px;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
-o-border-radius: 50px;
border-radius: 50px;
clip: rect(0px, 50px, 100px, 0px);
}
.hold {
position: absolute;
width: 100px;
height: 100px;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
-o-border-radius: 50px;
border-radius: 50px;
clip: rect(0px, 100px, 100px, 50px);
}
#pieSliceBlue{
-webkit-transform:rotate(0deg);
-moz-transform:rotate(0deg);
-o-transform:rotate(0deg);
transform:rotate(0deg);
}
#pieSliceBlue .pie {
background-color: #1b458b;
-webkit-transform:rotate(180deg);
-moz-transform:rotate(180deg);
-o-transform:rotate(180deg);
transform:rotate(180deg);
}
#pieSliceBlue2 {
-webkit-transform:rotate(180deg);
-moz-transform:rotate(180deg);
-o-transform:rotate(180deg);
transform:rotate(180deg);
}
#pieSliceBlue2 .pie {
background-color: #1b458b;
-webkit-transform:rotate(40deg);
-moz-transform:rotate(40deg);
-o-transform:rotate(40deg);
transform:rotate(40deg);
}
#pieSliceRed {
-webkit-transform:rotate(220deg);
-moz-transform:rotate(220deg);
-o-transform:rotate(220deg);
transform:rotate(220deg);
}
#pieSliceRed .pie {
background-color: #cc0000;
-webkit-transform:rotate(140deg);
-moz-transform:rotate(140deg);
-o-transform:rotate(140deg);
transform:rotate(140deg);
}
#pieSliceBlue .pie:hover{
background-color: yellow;
}
#pieSliceBlue2 .pie:hover{
background-color: yellow;
}
#pieSliceRed .pie:hover{
background-color: yellow;
}
<div class="pieContainer">
<div class="pieBackground"></div>
<div id="pieSliceBlue" class="hold"><div class="pie"></div></div>
<div id="pieSliceBlue2" class="hold"><div class="pie"></div></div>
<div id="pieSliceRed" class="hold"><div class="pie"></div></div>
</div>
Adding an :hover is ok for the slices blue2 and red but not for the first slice, where the hover works only on part of the slice.
http://jsfiddle.net/gvvsk/1/
The reason is that the pieSliceRed (the container for the .pie-div) is covering the pie-div contained in the pieSliceRed container, thus catching the hover event.
Since your solution most definately needs CSS3 support you can use pointer-events to bypass this behaviour. Try defining your css for the pieSliceRed this way instead:
#pieSliceRed {
pointer-events: none;
-webkit-transform:rotate(220deg);
-moz-transform:rotate(220deg);
-o-transform:rotate(220deg);
transform:rotate(220deg);
}
You can read more about the pointer-events here.
I know you can make a circle in CSS3 using the border radius hack. But is there any way to make them have segments like this picture? Is there a way of doing this through HTML and CSS but not JS?
Yes, you can get such slices of custom angles using either one of the following two methods:
If you don't need the slices to be elements themselves, the you can simply do it with one element and linear gradients - see this rainbow wheel I did last month.
If you need the slices to be elements themselves, then you can do it by chaining rotate and skew transforms - see this circular menu I did a while ago.
For #2, see also this very much simplified example I did right now.
.pie {
overflow:hidden;
position: relative;
margin: 1em auto;
border: dashed 1px;
padding: 0;
width: 32em; height: 32em;
border-radius: 50%;
list-style: none;
}
.slice {
overflow: hidden;
position: absolute;
top: 0; right: 0;
width: 50%; height: 50%;
transform-origin: 0% 100%;
}
.slice:first-child {
transform: rotate(15deg) skewY(-22.5deg);
}
.slice-contents {
position: absolute;
left: -100%;
width: 200%; height: 200%;
border-radius: 50%;
background: lightblue;
}
.slice:first-child .slice-contents {
transform: skewY(22.5deg); /* unskew slice contents */
}
.slice:hover .slice-contents { background: violet; } /* highlight on hover */
<ul class='pie'>
<li class='slice'>
<div class='slice-contents'></div>
</li>
<!-- you can add more slices here -->
</ul>
Yes you can: http://jsfiddle.net/elias94xx/3rx7w/, http://jsfiddle.net/elias94xx/3rx7w/2/
#chart {
width: 0;
height: 0;
border-right: 60px solid purple;
border-top: 60px solid transparent;
border-left: 60px solid transparent;
border-bottom: 60px solid transparent;
border-radius: 60px;
-moz-border-radius: 60px;
-webkit-border-radius: 60px;
}
<div id="chart"></div>
.chart {
position: absolute;
width: 0;
height: 0;
border-radius: 60px;
-moz-border-radius: 60px;
-webkit-border-radius: 60px;
}
#chart1 {
border-right: 60px solid red;
border-top: 60px solid transparent;
border-left: 60px solid transparent;
border-bottom: 60px solid transparent;
}
#chart2 {
border-right: 60px solid transparent;
border-top: 60px solid green;
border-left: 60px solid transparent;
border-bottom: 60px solid transparent;
}
#chart3 {
border-right: 60px solid transparent;
border-top: 60px solid transparent;
border-left: 60px solid blue;
border-bottom: 60px solid transparent;
}
#chart4 {
border-right: 60px solid transparent;
border-top: 60px solid transparent;
border-left: 60px solid transparent;
border-bottom: 60px solid yellow;
}
<div id="chart1" class="chart"></div>
<div id="chart2" class="chart"></div>
<div id="chart3" class="chart"></div>
<div id="chart4" class="chart"></div>
Source: http://www.paulund.co.uk/how-to-create-different-shapes-in-css
You can use html li element and some css transform to represent each slice of the circle.
The tricky part is the transform. In this case I've divided the circle into 5 slices.
The calculation is the following.
360/5=72 -> rotate
72+90=162 -> skewY
.sliceWrapper {
position: relative;
border: 1px solid black;
padding: 0;
width: 200px;
height: 200px;
border-radius: 50%;
list-style: none;
overflow: hidden;
}
.slice {
position: absolute;
left: -100%;
width: 200%;
height: 200%;
}
li {
overflow: hidden;
position: absolute;
top: -50%;
right: -50%;
width: 100%;
height: 100%;
transform-origin: 0% 100%;
}
li:first-child {
transform: rotate(0deg) skewY(162deg);
}
li:nth-child(2) {
transform: rotate(72deg) skewY(162deg);
}
li:nth-child(3) {
transform: rotate(144deg) skewY(162deg);
}
li:nth-child(4) {
transform: rotate(216deg) skewY(162deg);
}
li:nth-child(5) {
transform: rotate(288deg) skewY(162deg);
}
li:first-child .slice {
background: green;
}
li:nth-child(2) .slice {
background: tomato;
}
li:nth-child(3) .slice {
background: aqua;
}
li:nth-child(4) .slice {
background: yellow;
}
li:nth-child(5) .slice {
background: blue;
}
<ul class="sliceWrapper">
<li>
<div class="slice"></div>
</li>
<li>
<div class="slice"></div>
</li>
<li>
<div class="slice"></div>
</li>
<li>
<div class="slice"></div>
</li>
<li>
<div class="slice"></div>
</li>
</ul>
You can use a conic gradient
Conic gradients basically go around the shape, like a circle, from 0° to 360°.
Here is a basic conic gradient, with a circle:
div {
width: 500px;
height: 500px;
border-radius: 9999px;
background: red; /* fallback */
background: conic-gradient(red, orange, yellow, green, blue, purple);
}
<div></div>
Using color stops, we can then, magically, turn it into segments:
div {
width: 500px;
height: 500px;
border-radius: 9999px;
background: red; /* fallback */
background: conic-gradient(red 10%, orange 10%, orange 30%, yellow 30%, yellow 50%, green 50%, green 60%, blue 60%, blue 70%, purple 70%);
}
<div></div>
Optionally, if we only want one slice, we can now change this so we only have one colour, and now we're good to go :)
div {
width: 500px;
height: 500px;
border-radius: 9999px;
background: red; /* fallback */
background: conic-gradient(#0000 40%, red 40%, red 70%, #0000 70%);
}
<div></div>
I'm having an issue with some CSS I'm working on. The expected content is to be a containing box with four rounded corners that everything falls into. It works in Safari on the Mac, but not in Chrome or in iOS. In those browsers, the corners are squared for the .posttype and the image. I can't seem to figure out what is causing the issue. Any help will be great.
CSS:
.row { margin-bottom: 50px; }
.box { background: #eee; }
.shadow { -moz-box-shadow: 0px 3px 3px 0px #666; -webkit-box-shadow: 0px 3px 3px 0px #666; box-shadow: 0px 3px 3px 0px #666; }
.rounded { border-radius: 10px; -webkit-border-radius: 10px; -moz-border-radius: 10px; display: block; overflow: hidden; }
.posttype {
float: right;
position: relative;
width: 150px;
height: 150px;
text-transform: uppercase;
margin: -85px -85px 4px 4px;
-moz-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform:rotate(45deg);
overflow: hidden;
}
.posttype > p {
position: absolute;
bottom: 0;
width: 100%;
text-align: center;
font-size: 24px;
text-shadow: -1px -1px 1px #fff, 1px 1px 1px #000;
color: #fff;
opacity: 0.3;
}
.meta {
width: 110%;
margin: 5px -8px -8px -8px;
padding: 5px;
background-color: rgba(255,255,255,0.8);
box-shadow: inset -5px 1px 5px #555;
font-size: 10pt;
color: #555;
}
.photo { position: relative; }
.photo > p { padding: 0 8px; }
.photo > .meta { padding-left: 16px; padding-bottom: 16px; }
.photo > img, .photo > a > img { width: 100%; margin-bottom: 10px; }
.photo > .posttype { position: absolute; top: 0; right: 0; margin: -75px -75px 4px 4px; }
HTML:
<div class="row">
<div class="span7 box rounded shadow photo">
<img src="photo.jpg" alt="Alt" width="500">
<div class="posttype"><p>photo</p></div>
<p>This is a great picture.</p>
<hr class="clear">
<div class="meta">
<ul>
<li class="date"><i class="icon-time"></i> 7/29/12</li>
<li class="comments"><i class="icon-comment"></i> 3 Comments</li>
</ul>
<hr class="spacer">
<ul class="tags">
<li class="tags"><i class="icon-tags"></i></li>
<li class="tag">Tag1</li>
<li class="tag">Tag2</li>
</ul>
</div>
</div>
</div>
Live demo: Tinkerbin
The round borders are behind the image, add a padding-top look at this http://tinkerbin.com/fLyD5Cuf