Forum Moderators: not2easy
Add a 'padding' setting to the DIV.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style type="text/css">
.test {
width:200px;
height:200px;
background:red;
padding:25px;
position:relative;
}
div:after {
content:" ";
position:absolute;
top:15px;
left:15px;
right:15px;
bottom:15px;
border: 2px dashed #2D72C2;
}
</style>
</head>
<body>
<div class="test">IE8+ (+ other modern browsers) only</div>
</body>
</html>
Am I missing something?
content = " "; content = ""; To me, that implies that any <div> in the body will have the div:after properties assigned to it.
I think it's better to write .test:after instead of div:after . The first will add a pseudo element after any element that has a class of test, the latter will do it after every div in your document.
<style type="text/css">
.foobar {
width:200px;
height:200px;
background:#FCC;
padding:25px;
position:relative;
border: 1px dotted blue;
}
div.test:after {
content:" ";
position:absolute;
top:15px;
left:15px;
right:15px;
bottom:15px;
border: 2px dashed #2D72C2;
}
</style>
</head>
<body>
<div class="foobar">IE8+ (+ other modern browsers) only</div>
<div class="test foobar">IE8+ (+ other modern browsers) only</div>
</body>
The position:relative on the div container is imperative
I already gave browser support in the demo