Using gradients with corners is not suitable for your case, because (as King King has already pointed out in the comments) as the width increases, the angle of the gradient (or) of the percentage of the color balance must be changed to maintain shape. It is very difficult, therefore this method can be used only when the form has fixed sizes.
However, gradients can still be used with the to [side] [side] syntax, because gradients defined using this syntax can adapt to resizing containers. This method does not use pseudo-elements.
$(document).ready(function() { $('#increase').on('click', function() { $('.gradient').css('width', '300px').css('height', '500px'); }) })
div { display: inline-block; vertical-align: top; height: 300px; width: 100px; margin: 10px; color: beige; transition: all 1s; } .gradient { padding: 10px; background: linear-gradient(to top right, transparent 50%, tomato 50%) no-repeat, linear-gradient(to top right, transparent 0.1%, tomato 0.1%) no-repeat; background-size: 100% 100px, 100% 100%; background-position: 0% 100%, 0% -100px; } body { background: -webkit-radial-gradient(50% 50%, circle, aliceblue, steelblue); background: radial-gradient(circle at 50% 50%, aliceblue, steelblue); }
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="gradient">Some content</div> <br> <br> <button id="increase">Increase Width & Height</button>
Note that itβs best to make sure that the text does not flow into the slanted section of the form, because the wrap around the text to fit into the form is not straightforward.
Harry
source share