I had some problems with these two options, so I adapted some diagonal gradients from Lea Verou's excellent CSS Secrets book. I was thinking about creating a gradient inside the right and bottom borders using border-image
, but this property does not allow the use of edge targeting, à la border-right-image
, etc.
So, I decided to use a pseudo-element with two truncated corners, which seem to work very well. You must be careful to set the gradient width to 1.414, the size of half the indentation, as this will be the diagonal of the square (the square root of two). Also, since this is a pseudo-element, be careful with proper placement. It is interesting to hear what you think.
div { background: #bbb; padding: 1em 1.2em; width: 50%; margin: 0 auto; color: #111; font: 150%/1.2 Georgia, Palatino, Times, serif; position: relative; } div:after { content:" "; position:absolute; top:0; left: 0; width:100%; height:100%; padding: 1.42em; background: #000; background: linear-gradient(-135deg, transparent 2em, #000 0) top right, linear-gradient(#000, #000) padding-box bottom right, linear-gradient(45deg, transparent 2em, #000 0) bottom left; background-size: 50% 50%; background-repeat: no-repeat; -webkit-box-sizing: content-box; -moz-box-sizing: content-box; box-sizing: content-box; z-index: -1;
<div>This is a short sentence to demonstrate that our little div is responsive.</div>
source share