Home >Web Front-end >CSS Tutorial >Can I Use Percentages for Border Width in CSS?
Border Thickness in Percentages
Your endeavor to set border width in percentages has encountered a roadblock, as the CSS specification explicitly states that percentages are not supported for border widths.
However, a workaround exists that allows you to achieve the illusion of percentage borders. This involves creating a wrapper element with the desired border color as its background and setting its padding in percentages. Simultaneously, set the background of the element you want to border to white (or another suitable color).
Consider this example:
CSS:
.faux-borders { background-color: #f00; padding: 1px 25%; /* simulate border with padding */ } .content { background-color: #fff; }
HTML:
<div>
This non-scripted solution provides a method to simulate percentage borders without JavaScript.
The above is the detailed content of Can I Use Percentages for Border Width in CSS?. For more information, please follow other related articles on the PHP Chinese website!