How to make a double line border in CSS, each line in a different color without using background-image
?
For example like this:
Just take away the margins between the items so that their borders fit right against one another. Here's a complete example -- size of the borders made large so it's easy to see.
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<style type="text/css">
h2 { border-bottom: 10px solid blue; margin-bottom: 0; }
p { border-top: 10px solid green; margin-top: 0; }
</style>
</head>
<body>
<h2>Hiya</h2>
<p>La la la</p>
<h2>Hiya</h2>
<p>La la la</p>
</body>
</html>
You could do it like this:
also see FIDDLE
h2 {
border-bottom: 3px solid red;
}
p {
border-top: 3px solid blue;
margin-top: -20px;
padding-top: 20px;
}
Similar to what ADW said, in fact I'll edit his fiddle to help explain the difference.
In your description you explicitly described h2 followed by p should have the double border in between.
ADW's solution is good enough, only when there is only one p after the h2, but if there is another p, it will have a strange red line between the paragraphs. That's why we should only select the p which is immediately following a h2.
CSS selector for p immediately following h2 is h2 + p
Try this: http://jsfiddle.net/gR4qy/42/
h2 { border-bottom: solid pink;}
h2 + p { border-top: solid blue; }
This is nothing new. It's CSS 2.1! http://www.w3.org/TR/CSS2/selector.html
Unfortunately there's nothing I can think of to get rid of the blue border if the p is missing. You're on your own there :S
Sorry I have to get 50 points before I can comment and I dont know how to get points so I pposted this as a new answer :S
border-bottom: 1px solid blue;
box-shadow: 0 1px 0 red;
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.
h2 { border-bottom: solid blue;}
p { border-top: solid red; }
Will get you close, then play around with margins and padding until things line up.
http://jsfiddle.net/gR4qy/