如何使用CSS使边框丰富多彩?

时间:2013-09-18 17:46:25

标签: css

我在div中定义了一个border类:

<div class="border"></div>

.border {
border: 4px solid;
color: #E72665;
}

它为边框提供粉红色。但不仅仅是粉红色。我可以在边框中使用4种颜色,每种颜色覆盖25%,我该怎么做?

1 个答案:

答案 0 :(得分:2)

如果你的意思是每一方都有不同的颜色,你可以简单地将声明分解为特定的一面......

border-top: 1px solid red;
border-right: 1px solid blue;
border-bottom: 1px solid green;
border-left: 1px solid yellow;

根据你的评论......

实现你想要的唯一另一种方法是利用:after伪类来创建一个单独的元素,该元素具有4种颜色的背景渐变并将其用作边框。

以下是演示:http://jsfiddle.net/uLHR6/

.border {
    position: relative;
    width: 100px;
    height: 50px;
    background: #ccc;
}

.border:after {
    content: " ";
    display: block;
    position: absolute;
    width: 100px;
    height: 5px;
    bottom: 0;
background: #ff0000; /* Old browsers */
background: -moz-linear-gradient(left,  #ff0000 0%, #ff0000 24%, #00ff00 25%, #00ff00 49%, #0008ff 50%, #0008ff 74%, #f605ff 75%, #f605ff 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,#ff0000), color-stop(24%,#ff0000), color-stop(25%,#00ff00), color-stop(49%,#00ff00), color-stop(50%,#0008ff), color-stop(74%,#0008ff), color-stop(75%,#f605ff), color-stop(100%,#f605ff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left,  #ff0000 0%,#ff0000 24%,#00ff00 25%,#00ff00 49%,#0008ff 50%,#0008ff 74%,#f605ff 75%,#f605ff 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left,  #ff0000 0%,#ff0000 24%,#00ff00 25%,#00ff00 49%,#0008ff 50%,#0008ff 74%,#f605ff 75%,#f605ff 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left,  #ff0000 0%,#ff0000 24%,#00ff00 25%,#00ff00 49%,#0008ff 50%,#0008ff 74%,#f605ff 75%,#f605ff 100%); /* IE10+ */
background: linear-gradient(to right,  #ff0000 0%,#ff0000 24%,#00ff00 25%,#00ff00 49%,#0008ff 50%,#0008ff 74%,#f605ff 75%,#f605ff 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff0000', endColorstr='#f605ff',GradientType=1 ); /* IE6-9 */

}