Skip to content

Instantly share code, notes, and snippets.

@nternetinspired
Created May 5, 2015 12:43
Show Gist options
  • Select an option

  • Save nternetinspired/ca8a3092208d945f7d43 to your computer and use it in GitHub Desktop.

Select an option

Save nternetinspired/ca8a3092208d945f7d43 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
<div class="hero">
<div class="hero-overlay center">Centred Content</div>
<div class="hero-image">
<img src="http://placehold.it/600x400">
</div>
</div>
// ----
// Sass (v3.4.13)
// Compass (v1.0.3)
// ----
// Displays big text, on a colored background, with padding.
.hero {
position: relative;
z-index: 1;
&-image {
background-size: cover;
background-position: 50% 50%;
background-repeat: no-repeat;
width: 100%;
img {
width: 100%;
}
}
}
// Vertically and horizontally center thing of unknown size inside and parent of unknown size.
.center {
margin-top: 0;
position: absolute;
top: 50%;
left: 50%;
width: 100%;
text-align: center;
transform: translate(-50%, -50%);
}
.hero {
position: relative;
z-index: 1;
}
.hero-image {
background-size: cover;
background-position: 50% 50%;
background-repeat: no-repeat;
width: 100%;
}
.hero-image img {
width: 100%;
}
.center {
margin-top: 0;
position: absolute;
top: 50%;
left: 50%;
width: 100%;
text-align: center;
transform: translate(-50%, -50%);
}
<div class="hero">
<div class="hero-overlay center">Centred Content</div>
<div class="hero-image">
<img src="http://placehold.it/600x400">
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment