Can a similar shadow effect be achieved using CSS only?
Absolutely, by utilizing pseudoelements, box shadows, and 2D transformations – specifically, through rotation. An example demonstrating this is provided below.
Is this method compatible across different browsers?
To some extent. The preferred code may not be fully supported in older versions of IE. To ensure compatibility, certain compromises must be made, which are outlined below:
Here's the breakdown of support:
:before
and :after
– IE8+ only. For broader compatibility, consider replacing these with less-semantic div
elements.
rotation
– IE6+ with specific IE rules; details on these rules can be found at the end of the example.
box-shadow
– IE9+. To enable these shadows to work in IE6+, you may utilize CSSPie.
Sample of optimal code
Here is a quick demonstration to kick-start your project.
<div id="board">
Insert image here!
</div>
CSS
#board {
position: absolute;
left: 50px;
top: 50px;
background: #e5e5e5;
text-align: center;
width: 100px;
height: 100px;
}
#board:before {
z-index: -1;
position: absolute;
content: "";
bottom: 0;
left: 5px;
width: 5px;
height: 50%;
background: rgba(0, 0, 0, 0.7);
-webkit-box-shadow: -5px 0 10px rgba(0,0,0, 0.7);
-moz-box-shadow: -5px 0 10px rgba(0, 0, 0, 0.7);
box-shadow: -5px 0 10px rgba(0, 0, 0, 0.7);
-webkit-transform: rotate(6deg);
-moz-transform: rotate(6deg);
-o-transform: rotate(6deg);
-ms-transform: rotate(6deg);
transform: rotate(6deg);
}
#board:after {
z-index: -1;
position: absolute;
content: "";
bottom: 0;
right: 5px;
width: 5px;
height: 50%;
background: rgba(0, 0, 0, 0.7);
-webkit-box-shadow: 5px 0 10px rgba(0,0,0, 0.7);
-moz-box-shadow: 5px 0 10px rgba(0, 0, 0, 0.7);
box-shadow: 5px 0 10px rgba(0, 0, 0, 0.7);
-webkit-transform: rotate(-6deg);
-moz-transform: rotate(-6deg);
-o-transform: rotate(-6deg);
-ms-transform: rotate(-6deg);
transform: rotate(-6deg);
}
What next steps should I take?
- You may need to implement rotation syntax for early IE versions or use a JavaScript library to add support, as detailed here.
- If you desire the shadows to have a cutoff effect like in your image, consider covering the excess part of the shadow with an element positioned beneath it.
- This implementation was done quickly, so adjustments may be needed to achieve the desired shadow appearance.