Home > Article > Web Front-end > How Can I Draw a Triangle in the Corner of a Div Using Absolute Positioning?
You can easily draw triangles in the corner of divs by utilizing absolute positioning. For a more dynamic approach, consider using percentage values instead of fixed pixel values.
To achieve the desired result, follow these steps:
<code class="html"><div class="container"> <div class="triangle"></div> </div></code>
<code class="css">.container { position: absolute; top: 5%; left: 5%; width: 60%; height: 30%; background: black; color: white; border-radius: 12px; overflow: hidden; } .triangle { width: 0; height: 0; border-style: solid; border-width: 0 30px 30px 0; border-color: transparent #608A32 transparent transparent; right: 0; top: 0; position: absolute; }</code>
Using this method allows for flexibility in positioning and styling the triangle, making it a versatile solution for different design requirements and container sizes.
The above is the detailed content of How Can I Draw a Triangle in the Corner of a Div Using Absolute Positioning?. For more information, please follow other related articles on the PHP Chinese website!