Home >Web Front-end >CSS Tutorial >How Can I Create Multi-Colored Borders Using CSS?
Multi-Colored Borders: A CSS Solution
Crafting borders with multiple colors can enhance the visual appeal of any web element. One method to achieve this effect is through the use of pseudo-elements, but a more straightforward approach involves the border-image property.
The border-image property enables you to specify an image to be used as the border of an element. In this case, a linear gradient is used to create the multi-color effect. Consider the following example:
.fancy-border { width: 150px; height: 150px; text-align: center; border-top: 5px solid; border-image: linear-gradient(to right, grey 25%, yellow 25%, yellow 50%, red 50%, red 75%, teal 75%) 5; }
Within the
<div class="fancy-border"> my content </div>
This code will create a 150px x 150px box with a multi-colored top border. The linear gradient defines the sequence of colors used for the border: grey (25%), yellow (25%), yellow (50%), red (50%), red (75%), and teal (75%). The 5 at the end of the border-image property specifies the width of the border in pixels.
The above is the detailed content of How Can I Create Multi-Colored Borders Using CSS?. For more information, please follow other related articles on the PHP Chinese website!