Skip to content

Instantly share code, notes, and snippets.

@JoeNoPhoto
Last active October 18, 2015 19:23
Show Gist options
  • Save JoeNoPhoto/40902089a6e259fbcfaf to your computer and use it in GitHub Desktop.
Save JoeNoPhoto/40902089a6e259fbcfaf to your computer and use it in GitHub Desktop.
Vertically Centered Text on a Full Sized BG Image
@mixin image-spacer($ar: 1.00, $max-height: 600px, $min-height: 0, $container-width: 1.00) {
@if $min-height <= 1.00 and $min-height > 0 {
$container-width: $min-height;
$min-height: 0;
}
&:before {
content: '';
display: inline-block;
padding-top: $ar * 100%;
vertical-align: middle;
}
@media (min-width: ($max-height / ($container-width * $ar))) {
height: $max-height;
&:before {
padding-top: 0;
height: 100%;
}
}
@media (max-width: ($min-height / ($container-width * $ar))) {
height: $min-height;
&:before {
padding-top: 0;
height: 100%;
}
}
}
// Usage:
.my-module {
@include image-spacer(.665, 450px);
background: url('http://c3.staticflickr.com/7/6002/5959488791_f126825d38_b.jpg') no-repeat center center;
background-size: cover;
text-align: center;
.my-module-content {
display: inline-block;
position: relative;
width: 75%;
vertical-align: middle;
z-index: 10;
h1 {
color: #fff;
}
h3 {
color: #fff;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment