I'm trying to replicate the following blur effect with pure HTML/CSS. My current appraoch uses 2 images, the original cover-image, then, a 2nd copy of the image blurred-bg-image using CSS filter: blur(5px);.
Desired effect:
source
I can't find any way to keep the bottom portion the height of the toolbar while also retaining a background-image equal to the dimensions of the entire cover-image.
overflow: hidden doesn't work on a child element when the parent is anything but position: relative. But if the parent is relative, the inner blurred-bg-image is not the same dimensions as the cover-image
Here is the basic setup:
<div class="cover-image">
<div class="toolbar">
<div class="blurred-bg-image"></div>
</div>
</div>
The only solution I can find so far is to use clip rect() on blurred-bg-image, then calculate where to clip it to. But, this is not responsive and includes JS into the mix.
Here is a CodePen by the OP showing the end result.
The Method
You can use the method described here on CSS Tricks.
This method utilizes the following:
absolute positioning
transforms
one image for the background and blur effect
You'll have to adjust things with media queries, but that's not difficult. The only main drawback I see is that you have to set a fixed height on the toolbar content, because that height is used in the transforms. But again, that's easily done with media queries.
See the following snippet for the source and demo. I put some comments in the CSS.
html,
body {
width: 100%;
height: 100%;
}
.cover-image {
position: relative;
max-width: 1860px;
width: 100%;
max-height: 560px;
height: 100%;
overflow: hidden;
background-color: #005FE5;
}
.toolbar {
position: absolute; /* put .toolbar at the bottom of .cover-image */
bottom: 0;
left: 0;
z-index: 1;
width: 100%;
height: 100%;
overflow: hidden; /* keep pseduo-element from breaking out */
-webkit-transform: translateY(100%) translateY(-10rem); /* translate down all the way, then back up by height of .toolbar-content */
-moz-transform: translateY(100%) translateY(-10rem);
-ms-transform: translateY(100%) translateY(-10rem);
-o-transform: translateY(100%) translateY(-10rem);
transform: translateY(100%) translateY(-10rem);
}
/* the background will be the same for both elements but we will blur the pseudo-element later */
.cover-image,
.toolbar::before {
background-image: url("https://dl.dropboxusercontent.com/s/3vzuc6vmfito1zg/austin-cityscape-night-hdr-1.jpg?dl=0");
background-repeat: no-repeat;
background-position: center bottom;
background-size: cover; /* scales the background accordingly */
}
/* use this pseudo-element for the blur effect */
.toolbar::before {
content: "";
position: absolute;
bottom: 0;
left: 0;
z-index: -1;
width: 100%;
height: 100%;
-webkit-transform: translateY(-100%) translateY(10rem); /* translate inversely to what we translated .toolbar */
-moz-transform: translateY(-100%) translateY(10rem);
-ms-transform: translateY(-100%) translateY(10rem);
-o-transform: translateY(-100%) translateY(10rem);
transform: translateY(-100%) translateY(10rem);
-webkit-filter: blur(10px); /* finally! the blur effect */
filter: blur(10px);
}
.toolbar-content {
position: relative;
height: 10rem; /* use this value in the transforms */
color: #FFF;
}
.toolbar-content ul {
position: absolute;
top: 50%;
left: 5%;
margin: 0;
padding: 0;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-ms-transform: translateY(-50%);
-o-transform: translateY(-50%);
transform: translateY(-50%);
list-style: none;
}
.toolbar-title {
color: #A6BFC9;
text-transform: uppercase;
}
.edit-profile {
position: absolute;
top: 50%;
right: 5%;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-ms-transform: translateY(-50%);
-o-transform: translateY(-50%);
transform: translateY(-50%);
-webkit-appearance: none;
background-color: #00A9F3;
border: none;
}
#media only screen and (max-width: 66.25rem) {
.toolbar-content ul li {
margin-bottom: 0.25rem;
}
.toolbar-title,
.toolbar-detail {
display: inline-block;
}
.toolbar-title::after {
content: ":";
}
}
#media only screen and (min-width: 66.3125em) {
.toolbar {
-webkit-transform: translateY(100%) translateY(-6.25rem);
-moz-transform: translateY(100%) translateY(-6.25rem);
-ms-transform: translateY(100%) translateY(-6.25rem);
-o-transform: translateY(100%) translateY(-6.25rem);
transform: translateY(100%) translateY(-6.25rem);
}
.toolbar::before {
-webkit-transform: translateY(-100%) translateY(6.25rem);
-moz-transform: translateY(-100%) translateY(6.25rem);
-ms-transform: translateY(-100%) translateY(6.25rem);
-o-transform: translateY(-100%) translateY(6.25rem);
transform: translateY(-100%) translateY(6.25rem);
}
.toolbar-content {
height: 6.25rem;
}
.toolbar-content ul li {
display: inline-block;
padding: 0.625rem 1.25rem;
text-align: center;
}
}
<div class="cover-image">
<div class="toolbar">
<div class="toolbar-content">
<ul>
<li>
<div class="toolbar-title">Edad</div>
<div class="toolbar-detail">20 años</div>
</li>
<li>
<div class="toolbar-title">Cumpleaños</div>
<div class="toolbar-detail">8 de septiembre de 1994</div>
</li>
<li>
<div class="toolbar-title">Primera Conexión</div>
<div class="toolbar-detail">14 de enero de 2009</div>
</li>
<li>
<div class="toolbar-title">Klout</div>
<div class="toolbar-detail">87</div>
</li>
<li>
<div class="toolbar-title">Twitter</div>
<div class="toolbar-detail">1.806</div>
</li>
<li>
<div class="toolbar-title">Facebook</div>
<div class="toolbar-detail">345</div>
</li>
</ul>
<button class="edit-profile" type="button">Editar perfil</button>
</div>
</div>
</div>
<div class="some-other-content">
<p>You can add more content here</p>
<p>You can add more content here</p>
<p>You can add more content here</p>
<p>You can add more content here</p>
<p>You can add more content here</p>
<p>You can add more content here</p>
<p>You can add more content here</p>
<p>You can add more content here</p>
<p>You can add more content here</p>
</div>
Hacked away at this for a while today. Here is what I got:
glass.html
<html><head><link rel="stylesheet" type="text/css" href="glass.css"/></head>
<body>
<div id="bkgrd">
<div class="blur-bkgrd-position cropper flip ">
<div class="blur-bkgrd-position glass flip">
</div>
</div>
</div>
</body>
glass.css
#bkgrd{
position:absolute; /*align very top left */
top:0; /*align very top left */
left:0; /*align very top left */
width: 100%; /* full screen for background cover/contain */
padding-top: 56.25%; /* helps "bkgrd-size contain" stretch to full width by breaking height limit */
/*image*/
background-image: url(yourbackground.jpg);
background-size: contain; /*responsive width-wise, no js */
background-repeat: no-repeat;
overflow: hidden;
}
.blur-bkgrd-position {
position:absolute;
top:50%; /*sets up cut off point*/
left:0; /*align very left */
width: 100%; /* full screen for background cover/contain */
padding-top: 56.25%; /* helps "bkgrd-size contain" stretch to full width by breaking height limit */
}
.glass {
/*blurred image*/
background:
/* dark blue */
linear-gradient(
rgba(0, 0, 30, 0.45),
rgba(0, 0, 30, 0.45)
),
url(yourbackground.jpg);
background-size: contain; /*responsive width-wise, no js */
background-repeat: no-repeat;
background-position: center bottom.
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
}
.cropper {
overflow: hidden; /* performs the cropping */
}
/* apply to both .cropper and .glass */ /* enables crop from the top */
.flip {
-webkit-transform: rotate(180deg);
-moz-transform: rotate(180deg);
-ms-transform: rotate(180deg);
-o-transform: rotate(180deg);
transform: rotate(180deg);
}
Basically, we got two identical background images except one has a tint and blur effect, and is wrapped by an upside-down cropper.
Codepen: http://codepen.io/vtange/pen/MajweX
Helpful link: https://css-tricks.com/crop-top/
I've added the background image to the toolbar using ::before, which is positioned at the top of the toolbar. The image area and the pseudo element height should use a root based units, such as vh or rem, so they will be the same size regardless of their container size. In addition, the pseudo element background settings are identical to those of the main background. The pseudo element is blurred, and excess background is removed using the toolbar's overflow: hidden.
Resize the results panel in this Fiddle demo.
html, body {
margin: 0;
padding: 0;
}
.top-image {
position: relative;
min-height: 100px;
}
.top-image, .toolbar::before {
height: 50vh; /** the image and the blurred area height **/
background: url('http://www.theplanningboardroom.net/wp-content/uploads/2011/06/sydney-city-buildings.jpg') no-repeat;
background-size: cover;
}
/** the .toolbar::before is position at the bottom of the toolbar, so excess height goes up **/
.toolbar, .toolbar::before {
position: absolute;
right: 0;
bottom: 0;
left: 0;
}
.toolbar {
z-index: 1;
/** height can also be percentage such as 20% **/
height: 100px;
/** hide the rest of the background ::before **/
overflow: hidden;
/** some styling for the text and controls **/
box-sizing: border-box;
padding: 10px;
text-align: center;
}
.toolbar::before {
z-index: -1;
display: block;
/** the height is full screen height **/
-webkit-filter: blur(5px);
filter: blur(5px);
content:'';
}
<div class="main">
<div class="top-image">
<div class="toolbar">
text and controls
</div>
</div>
<div>
<p>The content</p>
</div>
</div>
If you don't wish the toolbar to be on the edge of the image, you can position it anywhere you wish inside it. Just set the toolbar's left, right, and bottom, and .toolbar::before properties the negative value (demo):
.toolbar {
position: absolute;
right: 100px;
bottom: 50px;
left: 100px;
}
.toolbar::before {
position: absolute;
right: -100px;
bottom: -50px;
left: -100px;
}
I don't know why you're getting problem in doing this, I was able to do it by using another div extending it fully wide and height equal to the toolbar and then set the same background-image and then blurred it.
Here is the code-
html,
body {
margin: 0;
padding: 0;
}
#container {
width: 100%;
background: black url('http://tinyurl.com/pgfnxag') bottom center no-repeat;
background-size: 100% auto;
position: relative;
overflow: hidden;
color: white;
font-size: 30px;
text-align: center;
}
#glass {
background-color: rgba(255, 255, 255, 0.25);
padding: 35px 0;
width: 100%;
color: white;
position: absolute;
bottom: 0;
border-top: 1px solid rgba(255, 255, 255, 0.2);
}
#blurred {
position: absolute;
width: 100%;
background: url('http://tinyurl.com/pgfnxag') bottom center no-repeat;
background-size: 100% auto;
filter: blur(5px);
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
top: 0;
left: 0;
height: 100%;
}
#content {
z-index: 999;
display: block;
position: absolute;
top: 50%;
left: 50%;
font-size: 20px;
font-weight: 100;
transform: translate(-50%, -50%);
font-family: Segoe UI;
text-align: center;
}
<div id="container">This is content above blurred part... Lorem ipsum dolor sit amet... and after that so more contents can go here..
<br />
<br />
<br />
<br />
<br />
<br />
<div id="glass">
<div id="blurred"></div>
<div id="content">Here goes the content..</div>
</div>
</div>
Fiddle demo to play with height of #glass and edit contents present in #content, the #blurred is the div holding the same background-image. The real trick here was to set all background properties (background-size, background-position, etc) exactly same as the #container.
UPDATE: changed to background-size: 100% auto;, now works well for any height or width of container or viewport.
EDIT: Removed all height properties, now its fully responsive! Run Code Snippet above.
Backdrop filters can do this, but are currently working only in Safari with the -webkit- prefix (and Chrome if you enable "Experimental Web Platform Features").
.toolbar{
-webkit-backdrop-filter: blur(5px);
backdrop-filter: blur(5px);
}
More info here.
body {
background: url(https://farm2.staticflickr.com/1551/25178575880_1449360954_k_d.jpg);
background-size: cover;
padding: 0;
margin: 0;
}
.box {
border-bottom: 1px solid rgba(0, 0, 0, 0.5);
-webkit-backdrop-filter: blur(6px);
backdrop-filter: blur(6px);
padding: 10px;
color: #fff;
font: 24px Arial, sans-serif;
background: rgba(255, 255, 255, 0.25);
}
<div class="box">
test box
</div>
Related
I have the following problem with my hexagons. With the code below it works fine and the hexagon stays within its container.
.hexagon-2 .content {
position: absolute;
z-index: 2;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
padding: 30px;
text-align: center;
}
.wrapper {
width: 100%;
/* This is the only value you need to change */
}
.container-2 {
position: relative;
width: 100%;
padding-bottom: 86.6%;
/* This sets the height of the div to 86% of its width */
border: 1px dashed green;
/* Just for demonstration purposes*/
transform: rotate(90deg);
}
.hexagon-2 {
position: absolute;
/* so .hexagon isn't pushed out of .container by the padding */
left: 25%;
width: 50%;
height: 100%;
margin: 0 auto;
/* center .hexagon inside .container*/
background-color: red;
/* color of the hexagon */
}
.hexagon-2:before,
.hexagon-2:after {
display: block;
position: absolute;
/* otherwise :after is below the hexagon */
top: 0;
content: '';
width: 100%;
height: 100%;
background-color: inherit;
}
.hexagon-2:before {
-webkit-transform: rotate(60deg);
-moz-transform: rotate(60deg);
-ms-transform: rotate(60deg);
transform: rotate(60deg);
}
.hexagon-2:after {
-webkit-transform: rotate(120deg);
-moz-transform: rotate(120deg);
-ms-transform: rotate(120deg);
transform: rotate(120deg);
}
<div class="container">
<div class="row">
<div class="col-lg-6">
<div class="wrapper">
<div class="container-2">
<div class="hexagon-2">
<span class="content">Test test test</span>
</div>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="wrapper">
<div class="container-2">
<div class="hexagon-2">
<span class="content">Test test test</span>
</div>
</div>
</div>
</div>
</div>
</div>
As long as I leave the hexagon that way, it works exactly as it should. However, when I rotate the hexagon 90 degrees, it goes wrong.
When I add this line to the .container-2 class:
transform: rotate(90deg);
The hexagons behave like this:
Because of the rotate they no longer fill out the container. Is there a clean way to solve this. I have already tried everything with these hexagons but no luck so far.
Anybody got an idea that I can stil rotate the hexagon but that it stil fills out the container?
Thanks
Just off the top of my head looking at this the reason it's not filling out the container is because the width of the hexagon is different. If you want it to fill exactly the same size when it is rotating make sure point to point is the same width as flat edge to flat edge. I did a quick check and point to point is 310 pixels and flat edge to flat edge is 263 pixels. Hope this helps.
So I really like this kind of special effect here https://www.w3schools.com/howto/howto_css_blurred_background.asp where you can blur out a background and have the text show up. The problem that I am currently having right now is that I want to add in another wallpaper for my second content below my first content. The first content is good. Now I want my second content to be in the second wallpaper as you scroll. Kind of like creating a parallax effect, but instead I am am creating my own unique website.
This time I want a blurring background (wallpaper number two) while having the stuff where I already want it placed and have it focus.
Is there a way to achieve that?
Starting where the bg-image2, I want the h1, and the p, inside bg-image2 to focus over the blurring background image.
NOTE: The wallpaper will not show in the snippet below because I already got the pictures I need in my folder which is located in my computer.
body,
html {
height: 100%;
}
* {
box-sizing: border-box;
}
.bg-image {
/* The image used */
background-image: url("images/wallpaper1.jpg");
/* Add the blur effect */
filter: blur(8px);
-webkit-filter: blur(8px);
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
/* Position text in the middle of the page/image */
.bg-text {
background-color: rgb(0, 0, 0);
/* Fallback color */
background-color: rgba(0, 0, 0, 0.4);
/* Black w/opacity/see-through */
color: white;
font-weight: bold;
border: 3px solid #f1f1f1;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 2;
width: 80%;
padding: 20px;
text-align: center;
}
.bg-image2 {
/* The image used */
background-image: url("images/wallpaper2.jpg");
/* Add the blur effect */
filter: blur(8px);
-webkit-filter: blur(8px);
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.profilePicture {
position: absolute;
left: 50%;
margin: 200px auto;
transform: translate(-50%, -50%);
}
<div class="bg-image"></div>
<div class="bg-text">
<h1>My name is Stackoverflow</h1>
<p>And I am a website</p>
</div>
<div class="bg-image2">
<!-- This is the part where I want my stuff to not be blurred and focus -->
<div class="profilePicture">
<img src="images/profilePic.jpg" style="width: 170px; height: 170px; border-radius:50%;">
<h1>This is a title</h1>
<p>This is just a paragraph</p>
</div>
</div>
Is that the result you are looking for?
https://codepen.io/anon/pen/exVRyy
All i did was to create a div around the bg-image2 and profilePicture, so that the blur on bg-image2 doesn't affect profilePicture, then set that div to position:relative; , so that the profilePicture can be placed in the middle like you did.
Here is your HTML edited:
<div class="bg-image"></div>
<div class="bg-text">
<h1>My name is Stackoverflow</h1>
<p>And I am a website</p>
</div>
<div class="bg-test">
<div class="bg-image2">
<!-- This is the part where I want my stuff to not be blurred and focus -->
</div>
<div class="profilePicture">
<img src="https://images.pexels.com/photos/1253661/pexels-photo-1253661.jpeg?cs=srgb&dl=android-wallpaper-bluhen-blume-1253661.jpg&fm=jpg" style="width: 170px; height: 170px; border-radius:50%;">
<h1>This is a title</h1>
<p>This is just a paragraph</p>
</div>
</div>
And the CSS:
body,
html {
height: 100%;
}
* {
box-sizing: border-box;
}
.bg-image {
/* The image used */
background-image: url("https://images.unsplash.com/photo-1507608616759-54f48f0af0ee?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80");
/* Add the blur effect */
filter: blur(8px);
-webkit-filter: blur(8px);
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
/* Position text in the middle of the page/image */
.bg-test {
position:relative;
}
.bg-text {
background-color: rgb(0, 0, 0);
/* Fallback color */
background-color: rgba(0, 0, 0, 0.4);
/* Black w/opacity/see-through */
color: white;
font-weight: bold;
border: 3px solid #f1f1f1;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 2;
width: 80%;
padding: 20px;
text-align: center;
}
.bg-image2 {
/* The image used */
background-image: url("https://whatthenewsblog.files.wordpress.com/2015/03/ecl-ann.jpg");
/* Add the blur effect */
filter: blur(8px);
-webkit-filter: blur(8px);
/* Full height */
height: 100vh;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.profilePicture {
position: absolute;
left: 50%;
top:50%;
margin: 0 auto;
transform: translate(-50%, -50%);
}
I was facing a similar issue. After a lot of searches, I found the perfect solution.
You can use backdrop-filter.
Your code:
body,
html {
height: 100%;
}
* {
padding: 0px;
margin: 0px;
box-sizing: border-box;
}
.bg-image {
/* The image used */
background-image: url("https://images.unsplash.com/photo-1507608616759-54f48f0af0ee?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80");
/* Add the blur effect */
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
/* Position text in the middle of the page/image */
.bg-test {
position:relative;
}
.bg-text {
background-color: rgb(0, 0, 0);
/* Fallback color */
background-color: rgba(0, 0, 0, 0.4);
/* Black w/opacity/see-through */
color: white;
font-weight: bold;
backdrop-filter: blur(8px);
border: 3px solid #f1f1f1;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 2;
width: 80%;
padding: 20px;
text-align: center;
}
.bg-image2 {
/* The image used */
background-image: url("https://blog.prezi.com/wp-content/uploads/2019/03/patrick-tomasso-208114-unsplash-1024x768.jpg");
/* Add the blur effect */
/* Full height */
height: 100vh;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.profilePicture {
backdrop-filter: blur(8px);
height: 100vh;
width: 100vw;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: absolute;
left: 50%;
color: white;
top:50%;
margin: 0 auto;
transform: translate(-50%, -50%);
}
<div class="bg-image">
<div class="bg-text">
<h1>My name is Stackoverflow</h1>
<p>And I am a website</p>
</div>
</div>
<div class="bg-test">
<div class="bg-image2">
<!-- This is the part where I want my stuff to not be blurred and focus -->
<div class="profilePicture">
<img src="https://images.pexels.com/photos/1253661/pexels-photo-1253661.jpeg?cs=srgb&dl=android-wallpaper-bluhen-blume-1253661.jpg&fm=jpg" style="width: 170px; height: 170px; border-radius:50%;">
<h1>This is a title</h1>
<p>This is just a paragraph</p>
</div>
</div>
</div>
I know its been so long since you asked and you got the answers.
Hope this will be helpful for someone else :)
I modified code from cryptomothy
I am trying to use the parallax effect on a site that has a fixed nav bar at the top of the page. Due to the way the parallax effect deals with overflows, the scroll bar appears to sit underneath the fixed nav bar at the top of the page.
I have included a fiddle to demonstrate this.
I have tried placing the fixed navbar div inside the parallax container. This moves the navbar beneath the scrollbar but also results in the navbar not fixing to the top of the page.
Here is my code so far...
HTML
<div class="navbar">NavBar</div>
<div class="parallax">
<div class="parallax_layer parallax_layer_back">
<img class="backgroundImage" src="https://images.pexels.com/photos/131212/pexels-photo-131212.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb">
</div>
<div class="parallax_layer parallax_layer_base">
<div class="title">Title</div>
<div class="content">Content area</div>
</div>
</div>
CSS
.parallax {
height: 100vh;
overflow-x: hidden;
overflow-y: initial;
perspective: 1px;
-webkit-perspective: 1px;
}
.parallax_layer {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.parallax_layer_base {
transform: translateZ(0);
-webkit-transform: translateZ(0);
}
.parallax_layer_back {
transform: translateZ(-1px);
-webkit-transform: translateZ(-1px);
}
.parallax_layer_back { transform: translateZ(-1px) scale(2); }
.parallax_layer_deep { transform: translateZ(-2px) scale(3); }
/* Example CSS for content */
* {
margin: 0;
padding: 0;
}
.title {
position: absolute;
left: 10%;
top: 30%;
color: white;
font-size: 300%;
}
.backgroundImage {
width: 100%;
height: auto;
}
.content {
margin-top: 100vh;
width: 100%;
height: 800px;
background-color: #e67e22;
}
.navbar {width:100%; position: fixed; z-index: 999; background-color: red;}
Based on your source code, I have made a few changes. I'll explain step by step.
Assume that your NavBar's height is 50px, I lower .parallax class 50px down by using margin-top:50px;.
Also, we need to change your NavBar's position property from fixed to absolute.
Now there will be 2 scrollbar, one for the body and one for the .parallax contents. To hide the body's scrollbar, which is unnecessary, we can use overflow:hidden; for body tag.
This time, you will see that your NavBar won't cover the scrollbar, but the bottom of the scrollbar is unfortunately unseeable since the contents is shifted 50px from to top. To solve this I use a simple Jquery code to set .parallax height equal to the remaining window's height.
You can have a look at the snippet.
$(document).ready(function(){
$(".parallax").css("height",$(window).height()-50);
});
.parallax {
margin-top:50px;
overflow-x: hidden;
overflow-y: initial;
perspective: 1px;
-webkit-perspective: 1px;
}
.parallax_layer {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.parallax_layer_base {
transform: translateZ(0);
-webkit-transform: translateZ(0);
}
.parallax_layer_back {
transform: translateZ(-1px);
-webkit-transform: translateZ(-1px);
}
/* Depth Correction */
.parallax_layer_back { transform: translateZ(-1px) scale(2); }
.parallax_layer_deep { transform: translateZ(-2px) scale(3); }
/* Example CSS for content */
* {
margin: 0;
padding: 0;
}
.title {
position: absolute;
left: 10%;
top: 30%;
color: white;
font-size: 300%;
}
.backgroundImage {
width: 100%;
height: auto;
}
.content {
margin-top: 100vh;
width: 100%;
height: 800px;
background-color: #e67e22;
}
.navbar {
width:100%;
position: absolute;
top:0;
z-index: 999;
background-color: red;
height:50px;
}
body{
overflow:hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="navbar"> NavBar </div>
<div class="parallax">
<div class="parallax_layer parallax_layer_back">
<img class="backgroundImage" src="https://images.pexels.com/photos/131212/pexels-photo-131212.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb">
</div>
<div class="parallax_layer parallax_layer_base">
<div class="title">Title</div>
<div class="content">Content area</div>
</div>
</div>
I have a main div (the red div in the fiddle) that has a smaller vertical tab on the side (the blue div in the fiddle).
The RED div is standard BUT the Blue div is rotated through 90 degrees (as I need to have vertical text in it). This is where the problems starts.
The red div is vertically positioned at 50% so it is in the middle of the page and locked with scrolling etc.
I want to align the blue div so that the top edge of the blue div is at the same Y position as the top edge of the red div.
I would prefer NOT to use jQuery but can do if required.
Desired output :
Fiddle is here : http://jsfiddle.net/kBKf6/
Here is the code I am using :
<div id="main" style="position: fixed; top: 50%; margin-top: -250px; left:0; height: 500px; width: 450px; background-color:red;">
Main Content Div
</div>
<div id="vertical_div" style="overflow:hidden; position: fixed; left:350px; height:40px; width:200px; margin: auto; background-color:blue; text-align:center; color:white; -webkit-transform: rotate(90deg) translate(-50%, -50%); -moz-transform: rotate(90deg) translate(-50%, -50%); -ms-transform: rotate(90deg) translate(-50%, -50%); -o-transform: rotate(90deg) translate(-50%, -50%); transform: rotate(90deg) translate(-50%, -50%);">
Side Tab
</div>
You don't need JS to align the rotated div. You can define a transform origin in CSS then, it becomes easy to align.
Side note : You can remove the -moz- and -o- vendor prefixes see caniuse
DEMO
HTML :
<div id="main">Main Content Div
<div id="verticaldiv">Side Tab</div>
</div>
CSS :
#main {
position: fixed;
top: 50%;
margin-top: -250px;
left:0;
height: 500px;
width: 450px;
background-color:red;
}
#verticaldiv {
overflow:hidden;
position: absolute;
left:100%;
bottom:100%;
height:40px;
width:200px;
background-color:blue;
text-align:center;
color:white;
-webkit-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
-ms-transform-origin:0 100%;
-webkit-transform-origin: 0 100%;
transform-origin: 0 100%;
}
You can also do it without relying on hardcoded sizes that move your div into position, but you need a wrapper around your .verticaldiv
demo:
http://jsfiddle.net/MCr6f/
demo 2:
http://jsfiddle.net/9LtKw/ (to show that different sizes don't matter)
html:
<div class="one">
Hello
<div class="pivot">
<div class="two">
Pretty!
</div>
</div>
</div>
css:
.one {
background: red;
position: relative;
float: left;
/*strange and difficult sizes*/
font-size: 3.237827em;
padding: 10px;
}
.pivot {
position: absolute;
top: 0;
right: 0;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
transform: rotate(90deg);
width: 0px;
height: 0px;
}
.two {
background: blue;
color: white;
position: absolute;
left: 0;
bottom: 0;
/*strange and difficult sizes*/
font-size: 12px;
padding: 0.3em;
}
In a Rails 3.2 app I am displaying user avatars using a responsive, flippable CSS circle. But due to padding needed on a parent element, the avatar is not centered in the circle.
How can I center this circle? Where possible, I would prefer to keep this semantically marked up with an img tag, rather than as a background image on a div.
Also, can this be optimized? I've a lot of nested divs at present!
The code is below, and a jsfiddle here.
<div class='responsive-container'>
<div class='responsive-inner'>
<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
<div class="flip-inner">
<div class="front">
<div class="circle">
<div class="circle-inner">
<%= image_tag #user.avatar %>
</div>
</div>
</div>
<div class="back">
<div class="circle">
<div class="circle-inner">
<%= #user.name %>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<style>
.responsive-container{
position: relative;
width: 50%;
}
.responsive-container:before{
content: "";
display: block;
padding-top: 100%;
}
.responsive-inner{
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.flip-container {
perspective: 1000;
-webkit-perspective: 1000; /* Safari and Chrome */
}
/* flip the pane when hovered */
.flip-container:hover .flip-inner, .flip-container.hover .flip-inner {
transform: rotateY(180deg);
-ms-transform:rotateY(180deg); /* IE 9 */
-webkit-transform:rotateY(180deg); /* Safari and Chrome */
}
.flip-inner {
transition: 0.6s;
-webkit-transition: 0.6s; /* Safari */
transform-style: preserve-3d;
-webkit-transform-style: preserve-3d; /* Safari and Chrome */
position: relative;
}
.front, .back {
backface-visibility: hidden;
-webkit-backface-visibility:hidden; /* Chrome and Safari */
-moz-backface-visibility:hidden; /* Firefox */
-ms-backface-visibility:hidden; /* Internet Explorer */
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.front {
z-index: 2;
}
.back {
transform: rotateY(180deg);
-ms-transform:rotateY(180deg); /* IE 9 */
-webkit-transform:rotateY(180deg); /* Safari and Chrome */
}
.circle {
width: 100%;
height: 0;
padding: 50% 0; //padding top & bottom must equal width
border-radius: 50%;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
overflow: hidden;
border: 1px #000 solid;
}
.circle-inner {
display: table;
width:100%;
}
.circle-inner img {
height: auto;
width: 100%;
}
.circle-inner p {
display: table-cell;
vertical-align: middle;
text-align: center;
}
</style>
why dont you use border-radius instead of circle? will be much easier i think.
http://bavotasan.com/2011/circular-images-with-css3/