Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make double lines border in CSS, each line in different color, without using background image?

Tags:

css

How to make a double line border in CSS, each line in a different color without using background-image?

For example like this:

enter image description here

Code:

<h2> heading 2 </h2> <p> paragraph text </p>  <h2> heading 2 </h2> <p> paragraph text </p> 

Note: I'm not considering IE 8, 7, 6

like image 348
Jitendra Vyas Avatar asked Apr 22 '11 07:04

Jitendra Vyas


People also ask

Can you add 2 borders in CSS?

Multiple borders in CSS can be done by box-shadow property. Generally, we can get a single border with border property. Box-shadow property is not for multiple borders, but still, we are creating multiple borders with box-shadow property.

Is it possible to style a border for different colors?

You can use the border-image property to create a gradient border with 4 colors.


2 Answers

I just found the way on google search and it's working good for me.

h2 {     border-bottom: 1px solid blue;     box-shadow: 0 1px 0 red;} 

Source : http://www.cvwdesign.com/txp/article/425/useful-tip-for-creating-double-borders-with-css3

Edit : I found another way to achieve multiple border using CSS 2.1 pseudo-elements

Support: Firefox 3.5+, Safari 4+, Chrome 4+, Opera 10+, IE8+

http://nicolasgallagher.com/multiple-backgrounds-and-borders-with-css2/

like image 123
Jitendra Vyas Avatar answered Sep 19 '22 14:09

Jitendra Vyas


You can do it with the :after pseudo element:

http://jsfiddle.net/aCgAA/

h2 { padding: 5px 0; border-bottom: solid 3px pink; font-weight: bold; position: relative; margin-bottom: 8px; }  h2:after { content: ''; border-bottom: solid 3px blue; width: 100%; position: absolute; bottom: -6px; left: 0; } 

This degrades gracefully to a single line if the :after selector is not available.

like image 36
methodofaction Avatar answered Sep 23 '22 14:09

methodofaction