Quick Tip: Multiple Borders with Simple CSS
Tutorial Details
- Topic: CSS Borders
- Difficulty: Intermediate
- Completion Time: 5 Minutes
Did you know that we can achieve multiple borders with simple CSS, by using the :after amd :before psuedo-classes? This is something I recently learned myself! I’ll show you how to add more depth to your designs, without images, in just a few minutes.
Prefer to watch this video on Screenr?
Final Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Multi-Borders</title>
<style>
body { background: #d2d1d0; }
#box {
background: #f4f4f4;
border: 1px solid #bbbbbb;
width: 200px;
height: 200px;
margin: 60px auto;
position: relative;
}
#box:before {
border: 1px solid white;
content: '';
width: 198px;
height: 198px;
position: absolute;
}
#box:after {
content: '';
position: absolute;
width: 196px;
height: 196px;
border: 1px solid #bbbbbb;
left: 1px; top: 1px;
}
</style>
</head>
<body>
<div id="box"></div>
</body>
</html>
In short, any browser that supports the :before and :after psuedo-elements (all major browsers) can take advantage of this effect. Of course, there are alternatives, including the use of box-shadow, as well as adding additional mark-up to the page; however, this is clean solution that you should definitely consider. Thanks for watching!
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
- http://www.johnwooten.info drumkeyjw
- http://www.friendevent.me Jon
- http://www.johnwooten.info drumkeyjw
- http://www.friendevent.me Jon
- http://www.johnwooten.info drumkeyjw
- ArnaudB
- Teddy
- http://www.flickr.com/armin_san Armin
- Thomas McDonald
- http://daniel-groves.co.uk Daniel Groves
- http://www.virtualerik.com Erik
- http://www.celtic7.com Luke
- http://aaronbentley.co.uk Aaron Bentley
- http://www.virtualerik.com Erik
- Mohamed Zahran
- http://www.limefox.co.uk Kent Website Designer
- http://emmediagroup.com Ted
- http://www.sayhelloharmony.com Brian Kulp
- http://www.nouveller.com/ Benjamin Reid
- http://filmsamlare.se/ Thim
- http://briancampbell.name Brian
- Teddy
- http://briancampbell.name Brian
- http://www.kreatech.net Ejaz
- http://www.nouveller.com/ Benjamin Reid
- Daniel
- JohnDel
- http://www.kopflos.eu Thomas
- Karl
- Gautam Chadha
- Pepitoto
- Christophor S.
- Gautam Chadha
- http://blog.creative-webdesign.info Andi
- jmarreros
- http://dougneiner.com Doug Neiner
- http://teslacreations.com Karol
- http://www.vectelligence.com Ilie Ciorba
- http://925html.com/ Eric Ferraiuolo
- Djkanna
- http://www.web.deverz.com Djkannad
- http://magplazza.com Mike
- http://www.alfystudio.com Ahmad Alfy
- http://www.obdsvs.com vas 5054a
- http://www.nb-nc.com Grinding machine
- http://www.kitfoxink.com Kit MacAllister
- http://www.xcellence-it.com Xcellence IT
- http://spasquini.interfree.it Sauro
- Diane
- Robbert
- http://nicolasgallagher.com Nicolas Gallagher
- Damion
- http://www.rittencommedia.dk Jimmy Rittenborg
- http://www.codecrunchers.net Kevin Groenendaal
- http://www.point269.com Dasha
- http://www.andrewckor.com/ Andrew Ckor
- Haziq
- http://www.sz-media.org Sz-Media.org
- http://www.jordanwalker.net Jordan Walker
- http://www.crearedesign.co.uk Steve Maggs
- Haziq
- Mike
- Laz
- http://www.u2u.ir Heam
- http://JonathanCutrell.com Jonathan Cutrell
- http://JonathanCutrell.com Jonathan Cutrell
- http://jonyarbor.name Jonathan Yarbor
- http://nicolasgallagher.com Nicolas Gallagher
- Jasper
