Languages
[Edit]
EN

CSS - div box with arrow in pure CSS

4 points
Created by:
JustMike
26730

In this short article we would like to show how to make div box with arrow in pure CSS.

Presented solution uses some trick that allows to set triangle shape for div elements. That divs are used later with absolute position as triangle with proper box. Using two triangle divs makes possible to ad additional border for arrows, what was presented below.

Quick solution:

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<body>
  <style>
    
    body { 
      	margin: 0;  /* <------------------------------------------- optional */
      	padding: 20px;  /* <--------------------------------------- optional */
    }

    /* --- solution --- */
    
    div.box {
      	position: relative;
      	width: 210px;  /* <---------------------------------------- optional */
    }

    div.box-arrow-border {
        position: absolute;
        top: -9px; right: 33px;
        border-left: 10px solid transparent;
        border-right: 10px solid transparent;
        border-bottom: 10px solid black;
        width: 0; height: 0;
    }

    div.box-arrow-background {
        position: absolute;
        left: -10px; top: 0;
        border-left: 10px solid transparent;
        border-right: 10px solid transparent;
        border-bottom: 10px solid white;
        width: 0; height: 0;
    }

    div.box-content {
      	padding: 10px;  /* <--------------------------------------- optional */
      	border: 1px solid rgba(0, 0, 0, 0.15);
        border-radius: 0.25rem;  /* <------------------------------ optional */
        box-shadow: 0 1px 3px rgba(200, 200, 200, 0.7);  /* <------ optional */
        overflow: hidden;  /* <------------------------------------ optional */
    }
    
  </style>
  <div class="box">
    <div class="box-arrow-border">
      <div class="box-arrow-background"></div>
    </div>
    <div class="box-content">
      Some content inside box...
    </div>
  </div>
</body>
</html>

 

Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - friendly IT community for everyone.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join