<ul class="list">
<li class="item">
<div class="block" data-direction="upward">upward</div>
</li>
<li class="item">
<div class="block" data-direction="rightward">rightward</div>
</li>
<li class="item">
<div class="block" data-direction="downward">downward</div>
</li>
<li class="item">
<div class="block" data-direction="leftward">leftward</div>
</li>
<li class="item">
<div class="block" data-direction="upper-left">upper-left</div>
</li>
<li class="item">
<div class="block" data-direction="upper-right">upper-right</div>
</li>
<li class="item">
<div class="block" data-direction="lower-right">lower-right</div>
</li>
<li class="item">
<div class="block" data-direction="lower-left">lower-left</div>
</li>
</ul>
@mixin triangle($direction, $width, $height, $color: currentColor) {
@if not index(upward rightward downward leftward upper-left upper-right lower-right lower-left, $direction) {
@error 'triangle()の方向は"upward","rightward","downward","leftward","upper-left","upper-right","lower-right","lower-left"から指定してください';
}
border-style: solid;
height: 0;
width: 0;
@if $direction == upward {
border-color: transparent transparent $color transparent;
border-width: 0 ($width / 2) $height ($width / 2);
}
@if $direction == rightward {
border-color: transparent transparent transparent $color;
border-width: ($height / 2) 0 ($height / 2) $width;
}
@if $direction == downward {
border-color: $color transparent transparent transparent;
border-width: $height ($width / 2) 0 ($width / 2);
}
@if $direction == leftward {
border-color: transparent $color transparent transparent;
border-width: ($height / 2) $width ($height / 2) 0;
}
@if $direction == upper-left {
border-color: $color transparent transparent transparent;
border-width: $height $height 0 0;
}
@if $direction == upper-right {
border-color: transparent $color transparent transparent;
border-width: 0 $height $height 0;
}
@if $direction == lower-right {
border-color: transparent transparent $color transparent;
border-width: 0 0 $height $height;
}
@if $direction == lower-left {
border-color: transparent transparent transparent $color;
border-width: $height 0 0 $height;
}
}
html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
body {
background: #f7f7f7;
color: #3a3a3a;
font-family: 'Open Sans', 'Helvetica Neue', 'Segoe UI', 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', Meiryo, sans-serif;
font-size: 1em;
line-height: 1.5;
padding: 5%;
}
.list {
display: grid;
gap: 8px;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
margin: auto;
max-width: 1200px;
}
.item {
display: grid;
padding: 32px;
place-items: center;
}
.block {
background-color: #cd5c5c;
border-radius: 4px;
box-shadow: 0 10px 12px -8px rgba(0, 0, 0, 0.35);
color: #f7f7f7;
font-size: 1rem;
line-height: 1.5;
min-width: 196px;
padding: 1.2em 1.5em;
position: relative;
text-align: center;
&::before {
content: '';
display: inline-block;
position: absolute;
}
}
[data-direction='upward'] {
&::before {
@include triangle(upward, 20px, 15px, #cd5c5c);
bottom: 100%;
left: calc(50% - 10px);
}
}
[data-direction='rightward'] {
&::before {
@include triangle(rightward, 15px, 20px, #cd5c5c);
left: 100%;
top: calc(50% - 10px);
}
}
[data-direction='downward'] {
&::before {
@include triangle(downward, 20px, 15px, #cd5c5c);
left: calc(50% - 10px);
top: 100%;
}
}
[data-direction='leftward'] {
&::before {
@include triangle(leftward, 15px, 20px, #cd5c5c);
right: 100%;
top: calc(50% - 10px);
}
}
[data-direction='upper-left'] {
&::before {
@include triangle(upper-left, 12px, 12px);
left: 6px;
top: 6px;
}
}
[data-direction='upper-right'] {
&::before {
@include triangle(upper-right, 12px, 12px);
right: 6px;
top: 6px;
}
}
[data-direction='lower-right'] {
&::before {
@include triangle(lower-right, 12px, 12px);
bottom: 6px;
right: 6px;
}
}
[data-direction='lower-left'] {
&::before {
@include triangle(lower-left, 12px, 12px);
bottom: 6px;
left: 6px;
}
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.