Achieving a slanted corner on a CSS box can be accomplished using various methods. One approach is described below:
This technique relies on creating a transparent border along the left side of a container and a slanted border along the bottom. The following code demonstrates how to implement this:
<code class="HTML"><div class="cornered"></div> <div class="main">Hello World</div></code>
<code class="CSS">.cornered { width: 160px; height: 0px; border-bottom: 40px solid red; border-right: 40px solid white; } .main { width: 200px; height: 200px; background-color: red; }</code>
This will produce a box with a slanted top-left corner at a 45-degree angle.
To allow for text within the slanted portion, an additional transparent border can be used. The modified code below illustrates this approach:
<code class="HTML"><div class="outer"> <div class="cornered">It's possible to put text up here too but if you want it to follow the slant you have to stack several of these.</div> <div class="main">Hello hello hello hello hello hello hello hello hello</div> </div></code>
<code class="CSS">.outer { background-color: #ccffff; padding: 10px; font-size: x-small; } .cornered { width: 176px; height: 0px; border-bottom: 40px solid red; border-left: 40px solid transparent; } .main { width: 200px; height: 200px; background-color: red; padding: 0 8px; }</code>
This method creates a slanted border that can display text along its length.
The above is the detailed content of How to Create a Slanted Corner on a CSS Box?. For more information, please follow other related articles on the PHP Chinese website!