-1

I need to create a shape like the one pictured below in just HTML and CSS. I am really not sure how to create the triangular shape at the bottom. The code I currently have is bare minimum because I am really not sure where to start.

    .newBadge {
        flex: inherit;
        height: 130px;
        width: 130px;
        background: linear-gradient(to right, grey, lightgray, lightgray ,grey 1900px);
        /* border-radius: 5px; */
        border: 5%;
        border-color: lightgray;
        border-style: inset;
      }
    
    .background{
    /* height: auto; */
    }
    
    .year{
        flex: auto;
        width: 0; 
        height: 0; 
        border-left: 20px solid transparent;
        border-right: 20px solid transparent;
        
        border-top: 1px solid #f00;
      
    }
<div class="newBadge">

    <div class="background">

    
        <div class="company">
            _______
        </div>

        <div class="title">
            ______
        </div>

        <div class="secondaryTitle">
            ______
        </div>

        <div class="rating">
            *****
        </div>

        <div class="year">
            2021
        </div>

    </div>

</div>

Shield shaped logo

BeerusDev
  • 1,444
  • 2
  • 11
  • 30
  • this might help [link](https://www.w3schools.com/graphics/svg_polygon.asp) – Hamid Jul 08 '21 at 20:32
  • 1
    Honestly, CSS is not the best solution for this problem. If it's for a test, fair enough, but otherwise you'll always certainly want to consider an image of sorts. – Obsidian Age Jul 08 '21 at 20:35
  • clip-path can help https://jsfiddle.net/z0w6erm2/ (mask too) – G-Cyrillus Jul 08 '21 at 20:58
  • Yeah, it is actually for real world problem. So when the shape is done, it is going to have multiple instances and but have different words where I have colored out. Does that make sense? – christian lance Jul 08 '21 at 21:06

4 Answers4

2

You can use the ::after pseudo-element along with borders:

div {
  height: 200px;
  width: 300px;
  background-color: #D5D3D4;
  position: relative;
}

div:after {
  content: '';
  position: absolute;
  top: 100%;
  left: 17%;
  margin-left: -50px;
  width: 0;
  height: 0;
  border-top: solid 50px #D2D0D1;
  border-left: solid 150px transparent;
  border-right: solid 150px transparent;
}
<div>

</div>

ideally I would like it to be about 20% thinner

div {
  height: 200px;
  width: 240px;
  background-color: #D5D3D4;
  position: relative;
}

div:after {
  content: '';
  position: absolute;
  top: 100%;
  left: 21%;
  margin-left: -50px;
  width: 0;
  height: 0;
  border-top: solid 50px #D2D0D1;
  border-left: solid 120px transparent;
  border-right: solid 120px transparent;
}
<div>

</div>
Spectric
  • 30,714
  • 6
  • 20
  • 43
0

Here is the HTML + CSS required to make a shield:

#parent {
    width: 300px;
    height: 300px;
}
 
#shield {
    position: relative;
    width: 100%;
    height: 90%;
    background-color: green;
    border-radius: 0 0 70% 70%;
    display: inline-block;
}
#shield:before, #shield:after {
    position: absolute;
    margin-top: 50%;
    content:"";
    left: 50%;
    top: 0;
    width: 50%;
    height: 53%;
    background: green;
    border-radius: 70% 70% 0 0;
    -webkit-transform: rotate(-61.5deg);
    -moz-transform: rotate(-61.5deg);
    -ms-transform: rotate(-61.5deg);
    -o-transform: rotate(-61.5deg);
    transform: rotate(-61.5deg);
    -webkit-transform-origin: 0 100%;
    -moz-transform-origin: 0 100%;
    -ms-transform-origin: 0 100%;
    -o-transform-origin: 0 100%;
    transform-origin: 0 100%;
}
#shield:after {
    background-color: green;
    left: 0;
    -webkit-transform: rotate(61.5deg);
    -moz-transform: rotate(61.5deg);
    -ms-transform: rotate(61.5deg);
    -o-transform: rotate(61.5deg);
    transform: rotate(61.5deg);
    -webkit-transform-origin: 100% 100%;
    -moz-transform-origin: 100% 100%;
    -ms-transform-origin: 100% 100%;
    -o-transform-origin: 100% 100%;
    transform-origin :100% 100%;
}
<a href="#">
  <div id="parent">
    <div id="shield">
      
    </div>
  </div>
</a>
BeerusDev
  • 1,444
  • 2
  • 11
  • 30
0

Use a canvas and mark the points.

<body>
  <canvas id="canvas" width="300" height="500"></canvas> 

  <script>
    var canvas = document.getElementById('canvas');
    if (canvas.getContext) {
        var context = canvas.getContext('2d');
        // Stroke color
        context.strokeStyle = "#000";
        context.beginPath();
        context.moveTo(50,100);
        context.lineTo(250,100);
        context.lineTo(250,300);
        // Your design
        context.stroke();
        // Fill with a color
        context.fillStyle = "#824EA8";
        context.fill();
    }
  </script>
</body>

In context.moveTo(50,100); 50 indicates x value from the left side of the canvas and 100 indicates y value from the top side of the canvas. Same order for others.

0
<svg width="2000" height="2000">
  <polygon points="50 50, 200 50, 200 200, 125 250, 50 200" style="fill: silver; stroke:black;" />
  
</svg>

You can make it with svg, just mark the points, and style it like You want.