Setting border widths using percentages is not directly supported in CSS. However, you can simulate this behavior using a combination of CSS techniques.
You can wrap the element you want to add borders to in a wrapper element with the following properties:
This technique creates the illusion of border percentages by using padding and background colors.
<br>.faux-borders {<br> background-color: #f00;<br> padding: 1px 25%; /<em> Simulate a 25% border on the sides </em>/<br>}</p> <p>.content {<br> background-color: #fff;<br>}</p> <p><div> <div class="content"></p> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">This element has simulated percentage borders.
This code wraps the inner element (content) in a wrapper element (faux-borders). The wrapper element has a red background color and 1px top and bottom padding. The inner element's background color is white.
The above is the detailed content of How Can I Create Percentage-Based Borders in CSS?. For more information, please follow other related articles on the PHP Chinese website!