Problem:
Creating a slanted edge for a div without using borders that will obscure underlying images.
Solution:
Slanted Pseudo Element:
Utilize a skewed pseudo element to create the slanted background while preserving the text content above it.
Transform Origin:
Set the transform origin of the pseudo element to the desired anchor point for the slant (right bottom corner in this case).
Skew Transformation:
Apply a skew transformation to the pseudo element to angle it accordingly (e.g., -45 degrees).
Overflow:
Use overflow: hidden; to hide any overflowing parts of the pseudo element.
Negative Z-Index:
Position the pseudo element behind the div content using a negative z-index.
Example Code:
div { position: relative; display: inline-block; padding: 1em 5em 1em 1em; overflow: hidden; color: #fff; } div:after { content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: #000; -webkit-transform-origin: 100% 0; -ms-transform-origin: 100% 0; transform-origin: 100% 0; -webkit-transform: skew(-45deg); -ms-transform: skew(-45deg); transform: skew(-45deg); z-index: -1; } body { background: url('https://farm3.staticflickr.com/2878/10944255073_973d2cd25c.jpg'); background-size: cover; }
Result:
This solution enables you to create responsive slanted edges for divs that won't affect their text content.
The above is the detailed content of How to Create a Responsive Slanted Edge for a Div Without Obscuring Underlying Images?. For more information, please follow other related articles on the PHP Chinese website!