.hex { position: relative; height: 100px; min-width: 100px; padding: 12px 24px; margin: 4px; float: left; font-weight: bold; text-align: center; } .hex.gradient-bg { color: white; } .hex.gradient-border { color: rgb(199, 41, 41); } .hex svg { position: absolute; height: 100%; width: 100%; top: 0px; left: 0px; z-index: -1; } path { stroke: url(#brdgrad); stroke-width: 7; } .hex.gradient-bg path { fill: url(#bggrad); } .hex.gradient-border path { fill: rgb(245, 246, 248); } span { display: block; margin-top: 50px; padding: 8px; transform: translateY(-50%); }
<svg width='0' height='0'> <defs> <linearGradient id='bggrad'> <stop offset='0%' stop-color='rgb(199, 41, 41)' /> <stop offset='100%' stop-color='rgb(243, 67, 54)' /> </linearGradient> <linearGradient id='brdgrad'> <stop offset='0%' stop-color='rgb(199, 41, 41)' /> <stop offset='100%' stop-color='rgb(243, 67, 54)' /> </linearGradient> </defs> </svg> <div class='hex gradient-border'> <svg viewBox='0 0 100 100' preserveAspectRatio='none'> <path d='M25,7 L75,7 93,50 75,93 25,93 7,50z' vector-effect='non-scaling-stroke' /> </svg> <span>Some text</span> </div> <div class='hex gradient-bg'> <svg viewBox='0 0 100 100' preserveAspectRatio='none'> <path d='M25,7 L75,7 93,50 75,93 25,93 7,50z' vector-effect='non-scaling-stroke' /> </svg> <span>Some very lengthy text</span> </div> <div class='hex gradient-bg'> <svg viewBox='0 0 100 100' preserveAspectRatio='none'> <path d='M25,7 L75,7 93,50 75,93 25,93 7,50z' vector-effect='non-scaling-stroke' /> </svg> <span>Some very lengthy text <br>with line break.</span> </div> <div class='hex gradient-bg'> <svg viewBox='0 0 100 100' preserveAspectRatio='none'> <path d='M25,7 L75,7 93,50 75,93 25,93 7,50z' vector-effect='non-scaling-stroke' /> </svg> <span>Some lengthy text without line break.</span> </div>