Home >Web Front-end >CSS Tutorial >How Can I Create a Responsive CSS Triangle with a Percentage-Based Width?
Responsive CSS Triangle with Percentage-Based Width
In CSS, we can create a triangle using borders by setting different widths for the top and bottom borders. However, when using percentages for the link width, the arrow's size cannot be adjusted dynamically based on the link's content.
Solution: Percentage-Based Triangle
To create a responsive triangle that adapts its size to the link's content, we can use a pseudo element with a skewed and rotated transformation:
.btn { ... padding-bottom: 15%; ... } .btn:after { content: ""; ... padding-bottom: 50%; ... transform: rotate(-30deg) skewX(30deg); }
Explanation:
Benefits:
The above is the detailed content of How Can I Create a Responsive CSS Triangle with a Percentage-Based Width?. For more information, please follow other related articles on the PHP Chinese website!