Skip to content

Instantly share code, notes, and snippets.

@stevenh512
Forked from nrrrdcore/apple-shadow.css
Created May 18, 2012 22:16
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenh512/2727859 to your computer and use it in GitHub Desktop.
Save stevenh512/2727859 to your computer and use it in GitHub Desktop.
Bending Shadows Backwards: Apple.com's Container CSS Sorcery
@import "compass/css3";
@mixin apple-shadow ($background-color: #f6f6f6,
$gradient-start-color: rgba(249, 249, 249, 1),
$gradient-stop-color: rgba(240, 240, 240, 1)) {
@include border-radius(0% 0% 100% 100% / 0% 0% 8px 8px);
@include box-shadow(rgba(0, 0, 0, 0.3) 0 2px 3px);
.inner {
border: 1px solid #FFF;
background: $background-color;
@include background(
linear-gradient(top, $gradient-start-color 50%, $gradient-stop-color 100%));
@include border-radius(5px);
@include box-shadow(inset 0 2px 1px rgba(255, 255, 255, 0.97));
}
}
.shadow-stuff {
-moz-border-radius: 0% 0% 100% 100% / 0% 0% 8px 8px;
-webkit-border-radius: 0% 0% 100% 100% / 0% 0% 8px 8px;
border-radius: 0% 0% 100% 100% / 0% 0% 8px 8px;
-moz-box-shadow: rgba(0,0,0,.30) 0 2px 3px;
-webkit-box-shadow: rgba(0,0,0,.30) 0 2px 3px;
box-shadow: rgba(0,0,0,.30) 0 2px 3px;
}
.container {
margin: 40 0 0 0;
background-color: white;
height: 200px;
border: 1px solid #FFF;
background: #F6F6F6;
background: -webkit-gradient(linear,left top,left bottom,color-stop(50%,rgba(249, 249, 249, 1)),color- stop(100%,rgba(240, 240, 240, 1)));
background: -webkit-linear-gradient(top,rgba(249, 249, 249, 1) 50%,rgba(240, 240, 240, 1) 100%);
background: -moz-linear-gradient(top,rgba(249, 249, 249, 1) 50%,rgba(240, 240, 240, 1) 100%);
background: -o-linear-gradient(top,rgba(249, 249, 249, 1) 50%,rgba(240, 240, 240, 1) 100%);
background: -ms-linear-gradient(top,rgba(249, 249, 249, 1) 50%,rgba(240, 240, 240, 1) 100%);
background: linear-gradient(top,rgba(249, 249, 249, 1) 50%,rgba(240, 240, 240, 1) 100%);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: inset 0 2px 1px rgba(255,255,255,.97);
-moz-box-shadow: inset 0 2px 1px rgba(255,255,255,.97);
box-shadow: inset 0 2px 1px rgba(255,255,255,.97);
}
<html>
<head>
<title>Bending shadows backwards</title>
<link rel="stylesheet" href="stylesheets/screen.css" type="text/css" />
</head>
<body>
<div class="shadow-stuff">
<div class="inner">
<div class="content">
Ohai!
</div>
</div>
</div>
</body>
</html>
# Require any additional compass plugins here.
# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "stylesheets"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "javascripts"
# You can select your preferred output style here (can be overridden via the command line):
# output_style = :expanded or :nested or :compact or :compressed
# To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true
# To disable debugging comments that display the original location of your selectors. Uncomment:
# line_comments = false
# If you prefer the indented syntax, you might want to regenerate this
# project again passing --syntax sass, or you can uncomment this:
# preferred_syntax = :sass
# and then run:
# sass-convert -R --from scss --to sass sass scss && rm -rf sass && mv scss sass
@import "apple-shadow";
.shadow-stuff {
margin: auto;
width: 50%;
@include apple-shadow;
.inner {
margin: 40px 0 0 0;
}
}
.content {
margin-top: 50px;
margin-bottom: 50px;
text-align: center;
font-size: 150%;
font-weight: bold;
}
@stevenh512
Copy link
Author

Disclaimer: I totally stole this from @nrrrdcore (the apple-shadow.css file is from her original gist), this is just a rough translation to SCSS using Compass mixins. 😁

@flipactual
Copy link

Just curious, so I figured I'd ask... when I'm using mixins, I want them to be reusable for different elements. You're including a height and margins in the mixin, which leads me to think you'd just reuse the css class if you wanted those specific dimensions to be reflected. Is there something I'm missing?

@stevenh512
Copy link
Author

No, you're definitely right, I plan on putting a little more work into this. I think the margins are needed (would need to experiment a bit to know for sure lol) but colors and height should definitely not be hard-coded in the mixins.

@flipactual
Copy link

Just making sure. Very cool and useful regardless!

@stevenh512
Copy link
Author

Refactored this a bit, it's a little more configurable and reusable now and you were right about the margin (it's included in the screen.scss for display purposes, but not necessary in the mixin). You have to generate the stylesheet with Compass to see the results on the HTML page, but here's a screenshot.

Screenshot

Definitely a cool effect.

@flipactual
Copy link

flipactual commented May 19, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment