Pure CSS double and triple borders

G’Day,

Everyday we learn something and everyday we practise “Experiments”. I do that sort of stuff for fun all the time. This is sort of my favourite past time. Anyways as I am still doing some experiments with pseodu elements I thought I should give you this cool CSS trick that you can use safely in all major browsers

lets take a look at the CSS first

The CSS for Double borders

  1. .dtborder {
  2. position:relative; /*important! */
  3. border:5px solid #000;
  4. height:200px;
  5. width:200px;
  6. background: #f9f9f9;
  7. padding:30px;
  8. border-radius: 10px;
  9. }
  10. .dtborder:before {
  11. content:"";
  12. position: absolute;
  13. /*set margins in other words its positioning our added pseudo content*/
  14. top:5px;
  15. bottom:5px;
  16. left:5px;
  17. right:5px;
  18. border:5px solid #999;
  19. border-radius: 8px;
  20. }

The Markup

  1. <div>
  2. This text appears inside a double bordered div
  3. where you can control the gap between border lines.
  4. </div>

Demo

http://jaspreetchahal.org/examples/css-examples/double-css-borders.html

Result

lets now add one more border line to our above div

No need to change the markup but instead use the CSS below

The CSS for Triple borders

  1. .dtborder {
  2. position:relative;
  3. border:5px solid #000;
  4. height:210px;
  5. width:210px;
  6. background: #f8f8f8;
  7. padding:30px;
  8. border-radius: 9px;
  9. }
  10. .dtborder:before {
  11. content:"";
  12. position: absolute;
  13. top:5px;
  14. bottom:5px;
  15. left:5px;
  16. right:5px;
  17. border:5px solid #999;
  18. border-radius: 8px;
  19. }
  20.  
  21. .dtborder:after {
  22. content:"";
  23. position: absolute;
  24. top:15px;
  25. bottom:15px;
  26. left:15px;
  27. right:15px;
  28. border:5px solid #666;
  29. border-radius: 8px;
  30. }

Demo

http://jaspreetchahal.org/examples/css-examples/triple-css-borders.html

Result

So our result now will look like this

Important thing in above piece of CSS is element padding to give enough room for our borders.

I hope this was an exciting read for you.

Cheers

Advertisement

 

 

 

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Speak Your Mind

*

CommentLuv badge