Border Anomaly Over Gradients: Explained and Resolved
When applying a transparent border over an element featuring a linear-gradient background, unexpected behavior may arise. The left and right edges of the element exhibit distorted colors and appear flattened.
This effect stems from the border extending beyond the padding-box, where the linear-gradient repeats. The outer border area inherits the gradient colors, resulting in the anomalies witnessed on the left and right sides.
Solution: Employ Box-Shadow
To resolve this issue, consider utilizing a box-shadow:inset instead of a border. Box-shadows render within the padding-box, similar to backgrounds.
Modify the CSS as follows:
box-shadow: inset 0 0 0 10px rgba(0,0,0,0.2); padding: 10px;
Explanation:
Conclusion:
By comprehending the behavior of borders and gradients in relation to the padding-box, you can effectively resolve this anomalous effect and achieve the desired border-like appearance with a box-shadow.
The above is the detailed content of Why Do Transparent Borders Distort Linear Gradients, and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!