Skip to content

Instantly share code, notes, and snippets.

@smonn
Created August 19, 2015 13:49
Show Gist options
  • Save smonn/14085e1da9464fcaeabd to your computer and use it in GitHub Desktop.
Save smonn/14085e1da9464fcaeabd to your computer and use it in GitHub Desktop.
body {
margin: 0;
}
.fixed-size {
width: 430px;
height: 240px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -120px;
margin-left: -215px;
background-image: url('https://unsplash.it/1200/600');
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
}
.fixed-size--alt {
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 240px;
text-align: center;
}
.fixed-size--alt__align {
position: absolute;
top: 0;
left: 50%;
display: block;
width: 480px;
height: 100%;
margin-left: -240px;
overflow: hidden;
}
.fixed-size--alt__image {
width: auto;
height: 240px;
display: block;
}
.ratio-size {
position: relative;
background-color: #333;
width: 100%;
height: 240px;
overflow: hidden;
}
.ratio-size__content {
background-color: red;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
}
.center-box {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.center-box:before {
content: "";
margin-right: -.25em;
display: inline-block;
height: 100%;
vertical-align: middle;
}
.center-box__body {
display: inline-block;
vertical-align: middle;
width: 100%;
}
.spotlight {
text-align: center;
font-weight: bold;
font-size: 16px;
line-height: 1;
margin-top: 0;
margin-bottom: 0;
padding-left: 20px;
padding-right: 20px;
font-family: Arial, sans-serif;
color: white;
transition: font-size 200ms;
}
@media screen and (min-width: 320px) {
.spotlight {
font-size: 24px;
}
.fixed-size {
width: 640px;
height: 360px;
margin-top: -180px;
margin-left: -320px;
}
}
@media screen and (min-width: 480px) {
.spotlight {
font-size: 32px;
}
.ratio-size {
height: 0;
padding-bottom: 50%;
}
.fixed-size--alt {
height: 0;
padding-bottom: 50%;
}
.fixed-size--alt__image {
position: static;
margin-top: 0;
margin-left: 0;
width: 100%;
height: auto;
min-height: 240px;
}
.fixed-size--alt__align {
position: static;
display: inline;
margin-left: 0;
}
.fixed-size {
width: 860px;
height: 480px;
margin-top: -240px;
margin-left: -430px;
}
}
@media screen and (min-width: 768px) {
.spotlight {
font-size: 48px;
}
.fixed-size {
width: 1280px;
height: 720px;
margin-top: -360px;
margin-left: -640px;
}
}
@media screen and (min-width: 992px) {
.spotlight {
font-size: 64px;
}
.fixed-size {
width: 1600px;
height: 900px;
margin-top: -450px;
margin-left: -800px;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment