Unable to set background-colorpadding attributes and fields. They must be transparent or invisible and used exclusively for positioning purposes.
Nevertheless, I have heard this question many times, and I fully understand that I want to show additions and fields for purely educational purposes. So I created a simple little hack to represent box-model using CSS :beforeand :afterpsuedo-elements.
You cannot type color or fields, but let me suggest a little hack to make it look the way you can (without JavaScript!):
simulated box-model:
#box {
width: 150px;
height: 150px;
background: green;
position: relative;
border: 10px solid blue;
left: 50px;
top: 50px;
}
#box:before {
background: red;
content: 'border';
display: block;
position: absolute;
top: -30px;
left: -30px;
right: -30px;
bottom: -30px;
z-index: -1;
}
#box:after {
background: gray;
content: 'margin';
display: block;
position: absolute;
top: -50px;
left: -50px;
right: -50px;
bottom: -50px;
z-index: -2;
}
<div id="box">#box</div>
Run code source
share