0

I have defined a border class in a div:

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

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

It gives pink color to the border. But instead of pink only. I can 4 colors in borders each covering 25% how can I do that?

pynovice
  • 7,424
  • 25
  • 69
  • 109
  • something like this might help you: http://stackoverflow.com/questions/2717127/css3-gradient-borders. You might also use div's around the border and use a background image or color on each edge that you want a change of color. – scrappedcola Sep 18 '13 at 17:54

1 Answers1

2

If you mean each side a different color than you can simply break the declaration into specific sides...

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

Per your comment below...

The only other way to achieve what you want would be to utilize the :after pseudo-class to create a separate element that has a background gradient with your 4 colors and to use that as your border.

Here is a demo: 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 */

}
Michael
  • 7,016
  • 2
  • 28
  • 41
  • I don't want to break into 4 parts vertically. I want to break into 4 parts horizontally. – pynovice Sep 18 '13 at 17:51
  • Wonderfully, done but I have various issues. Sorry I am new to css. I don't want the grey part. The css I defined in the question took the full width page and only included the border. I just want to break that into four things. I don't want more stuffs. – pynovice Sep 18 '13 at 18:10
  • My demo of course needs to be adapted to your particular use case. Sounds like you managed it though. Good luck! – Michael Sep 18 '13 at 18:17