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
- arnold
- TahaH
- http://wildanr05.student.ipb.ac.id wildanr05
- http://www.xcellence-it.com Xcellence IT
- BJ
- http://jonyarbor.name Jonathan Yarbor
- David McGuigan
- http://NewHighScore.com rsturk
- Adam king
- http://www.darrenmcpherson.co.uk Darren McPherson
- Pako Adrian
- http://aninnovativeweb.com Sam Bowler
- http://nicolasgallagher.com Nicolas Gallagher
- http://twiiter.com/aelien AC
- http://arieff06.student.ipb.ac.id arieff
- http://www.danblee.com Dan B. Lee
- http://www.altinnet.com altin
- wolfdesign
- Christophe
- http://aninnovativeweb.tumblr.com Sam Bowler
- http://cloverpetals.com/log TasiaChiba
- http://www.o-theme.com Dian
- http://www.ricardozea.net Ricardo Zea
- t31os
- http://hkdobrev.blogspot.com Harry
- http://ageno.pl/ pozycjonowanie bielsko
- http://www.emmi-nail.bg ноктопластика
- http://arifr06.student.ipb.ac.id ardhan
- http://trisr06.student.ipb.ac.id tee are
- http://yuliantip06.student.ipb.ac.id yulianti
- http://tric06.student.ipb.ac.id utari
- dig
- http://nylens.nu Erik Blomqvist
- http://misoblog.net/ Miso
- http://www.josiahsprague.com Josiah
- http://www.kitfoxink.com Kit MacAllister
- http://www.jaffydesigns.com/ Jason
- http://chairila06.student.ipb.ac.id chai
- http://ekos06.student.ipb.ac.id Kojeje
- http://ericsons06.student.ipb.ac.id/ eric
- http://karimul.makhtidi08.student.ipb.ac.id dety
- http://bambang.wijonarko08.student.ipb.ac.id wij
- http://oki.maulana08.student.ipb.ac.id kai
- http://bcwebtech.info aromatech
- http://cmdesign.ca cmdesign
- http://nofel.saputra08.student.ipb.ac.id nofel
- http://asd.asd notme
- Sebastian
- Carl
- Nasi
- http://www.tenaxtechnologies.com java web development
- Dima
- http://myriadhues.wordpress.com farghana
- Otto
- bart
- http://myshadowself.com Can anyone spell M.O.N.G?
- www.WorldWebGuys.com
- http://www.WorldWebGuys.com/
- http://www.agah-iran.com farzad
- http://www.runtyrobot.com runtyrobot
- Levani
- http://AriaTemp.ir javad
- http://balics.net balics
- halma_artur
