I am trying to achieve frosted glass effect as described here: https://css-tricks.com/frosting-glass-css-filters/. In order to do this, I need to add :before element with the same background and apply blur effect.
Here's my HTML:
<div class="root">
<div class="content">
<p>Ok hello</p>
</div>
</div>
and CSS:
.root {
background: url('http://666a658c624a3c03a6b2-25cda059d975d2f318c03e90bcf17c40.r92.cf1.rackcdn.com/unsplash_527bf56961712_1.JPG') no-repeat center center fixed;
background-size: cover;
height: 400px;
}
.content {
position: relative;
top: 50%;
transform: translateY(-50%);
background-color: red;
padding-top: 16px;
padding-bottom: 16px;
}
.content:before {
content: "";
position: absolute;
width: 100%;
top: 0;
bottom: 0;
z-index: -1;
background: url('http://666a658c624a3c03a6b2-25cda059d975d2f318c03e90bcf17c40.r92.cf1.rackcdn.com/unsplash_527bf56961712_1.JPG') no-repeat center center fixed;
background-size: cover;
opacity: 0.5;
/* -webkit-filter: blur(5px); */
}
Here's the pen: http://codepen.io/anon/pen/MKgbKR
I can't seem to position the background of :before element correctly. It is always shifted vertically. I tried playing with translation of this element, adjust the background, but to no avail. The problem can be easily noticed in the right part of the image, especially if you try resizing the resulting document vertically.
I am an absolute beginner in CSS, so I'm out of ideas. Your help will be appreciated.
EDIT: I think I should clarify my requirements. I need to keep the content block centered vertically regardless of window size changes. The image should remain centered and cover the background. The content never changes.
This might not show correctly on the snippet box, test it on your site and lmk
.root {
background: url('http://666a658c624a3c03a6b2-25cda059d975d2f318c03e90bcf17c40.r92.cf1.rackcdn.com/unsplash_527bf56961712_1.JPG') no-repeat center center;
background-size: cover;
height: 600px;
}
.content {
position: relative;
top: 50%;
height: 200px;
transform: translateY(-50%);
background-color: red;
}
.content:before {
content: "";
position: absolute;
width: 100%;
top: 0;
bottom: 0;
z-index: -1;
background: url('http://666a658c624a3c03a6b2-25cda059d975d2f318c03e90bcf17c40.r92.cf1.rackcdn.com/unsplash_527bf56961712_1.JPG') no-repeat center center;
background-size: cover;
opacity: 0.5;
-webkit-filter: blur(5px);
}
<div class="root">
<div class="content">
<p>Ok hello</p>
</div>
</div>
Related
I'm trying to make the background-image of a parent stretched to a pseudo element.
I'm currently using the code below and it works in a sense that it's using the same image but the placement is not correct (see screenshot). I'd like this to be seamless.
.parent {
position: relative;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
.parent::after {
content: '';
position: absolute;
bottom: -15px;
left: 0;
width: 100%;
height: 15px;
background: inherit;
z-index: 1;
}
Setting the parent's background-attachement to fixed seems to make it work but then I get an unwanted parallax effect on the parent.
Is there a way to make this work in a way that allows me to stretch the background image but avoid parallax? All help much appreciated!
Make the pseudo element cover the whole element and only its background will be visible:
.parent {
position: relative;
background-image:url(https://picsum.photos/id/1018/800/800);
background-size: cover;
background-repeat: no-repeat;
background-position: center;
position:relative;
z-index:0;
height:100px;
}
.parent::after {
content: '';
position: absolute;
z-index:-1;
bottom: -15px;
left: 0;
width: 100%;
top:0;
background: inherit;
z-index: -1;
}
<div class="parent">
</div>
Trying to build out a hero style masthead with a transparent cover image, and a color tint overlay; then display some text on top of this. I am using bootstrap 3 as underlying framework.
I have my hero wrapped in a div, I then have two child div. One contains the background tint layer, the other contains the text/title.
The background div layer is breaking out of the parent wrapper div and covering the entire viewport below it. I'm not sure where i went wrong.
Fiddle of my broken attempt:
Fiddle
#page-title {
font-size: 2.2em;
padding: 20px 40px;
margin-bottom: 40px;
}
.bg-layer {
opacity: 0.75;
background-color: #f7f8fa;
position: absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
}
.bg-wrapper {
background-image: url(/whatever.png);
background-position: right center;
background-size: cover;
background-repeat: no-repeat;
background-attachment: scroll;
}
<div class="bg-wrapper">
<div class="bg-layer"></div>
<header id="page-title">
<div class="container">
About Us </div>
</header>
</div>
Add high z-index on .bg-layer, beacuse bootstrap CSS navbar Class default z-index is 1000
.bg-layer {
opacity: 0.75;
background-color: #f7f8fa;
position: absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
z-index:1001;;
}
https://jsfiddle.net/lalji1051/9b46x5yo/3/
All your code is absolutely fine, Just add this line position: relative;to the .bg-wraper class and you will get the desired result!
#page-title {
font-size: 2.2em;
padding: 20px 40px;
margin-bottom: 40px;
}
.bg-layer {
opacity: 0.75;
background-color: #f7f8fa;
background-color: #f005; /* just adding this for visibility*/
position: absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
}
.bg-wrapper {
background-image: url(/whatever.png);
background-position: right center;
background-size: cover;
background-repeat: no-repeat;
background-attachment: scroll;
/*Just this additionale property*/
position: relative;
}
<div class="bg-wrapper">
<div class="bg-layer"></div>
<header id="page-title">
<div class="container">
About Us </div>
</header>
</div>
I have following sets of css:
.spinner {
background-image: url('../assets/spinner.svg');
position: absolute;
top: 40%;
left: 45%;
height: 200px;
width: 200px;
background-repeat: no-repeat;
background-position: center;
}
.overlay {
height: 100%;
width: 100%;
background: black;
opacity: 0.3;
z-index: 9999;
display: block;
position: fixed;
}
and following html code:
<router-outlet>
<div *ngIf="fetchingData" class="overlay">
<div class="spinner"></div>
</div>
</router-outlet>
There shouldn't be any way the image should appear twice, but in few devices the image is appearing twice vertically. I increased .spinner height to 100% and image appears thrice vertically along the page.
Setting background-repeat-y: no-repeat; has no effect either. If I reduce the height for .spinner to say 100px, I get just one image, but I doubt that might also break in few devices.
Any ideas why the image shows twice.
I have a problem, as situated in the image:
When I am scrolling down, the background image I have (the blue one) gets a white area, while that should be blue too. The blue background should be blue everywhere, yet because it's skewed and I am using it as a fixed background image, it does not work, somehow.
HTML:
<div class="wrapper">
<p>Here comes some text and so on</p>
</div>
CSS:
.wrapper {
background: url("myimage.png");
background-attachment: fixed;
transform: skewY(3deg);
min-height: 500px;
}
The white background you can see, is the body background. It should not be there, yet it is, somehow. When I would remove background-attachment: fixed, it works, yet I want to have it fixed as I am using parallax scrolling.
So it looks like transform: skewY(3deg); and background-attachment: fixed are blocking each other. I tried adding z-index and so on, but nothing is working for me at the moment.
Is there a way to fix this?
To fix so that slope only occur at the bottom, use a pseudo.
For the skewY() to transform upwards, use transform-origin: right top;, then set overflow: hidden to the wrapper to clip the upper part and the slope is only visible at the bottom.
html, body {
margin: 0;
}
body {
background: red;
}
.wrapper {
position: relative;
height: 200px;
width: 100%;
min-height: 1500px;
overflow: hidden;
}
.wrapper.nr2::before {
content: '';
position: absolute;
left: 0;
top: 0;
background: url("http://www.planwallpaper.com/static/images/6790904-free-background-wallpaper.jpg");
height: 100%;
width: 100%;
transform: skewY(3deg);
transform-origin: right top;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.wrapper::before {
content: '';
position: absolute;
left: 0;
top: 0;
background: url("http://www.planwallpaper.com/static/images/6790904-free-background-wallpaper.jpg");
height: 100%;
width: 100%;
transform: skewY(3deg);
transform-origin: right top;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.wrapper div {
position: relative;
color: red;
font-size: 30px;
}
<div class="wrapper nr2">
<div>Some text</div>
</div>
<div class="wrapper">
<div>Some more text</div>
</div>
I have a webpage with an background-image with background-size:cover.
Now I want to overlay this background-image with certain div's, which contain additional informations. These div's have to be at an exact position relative to the background image, even though I resize the broswer window.
That's just one attempt that didn't work.
HTML
<body>
<div class="icon">
<div class="background picture_rendering"></div>
</body>
CSS
.background {
width:100%;
height:100%;
background-image: url(images/bg.jpg);
background-size: cover;
z-index: 0;
position: absolute;
}
.icon {
width: 100%;
height: 100%;
left: 0px;
top: 0px;
position: relative;
background-image: url('/images/icon.jpg');
background-size: 5% auto;
background-position: 227px center;
background-attachment: fixed;
}
It should be something like the map-tag: http://www.w3schools.com/tags/tag_map.asp But instead of links there should be icons.
I hope you understand :-)
Best regards,
The One
Basically you can create a parent or wrapper element which would have the background image and then place all the elements like icons etc inside this and do all your positioning etc. So I've created this for you:
CSS
.container {
background: url(http://www.w3schools.com/tags/planets.gif) no-repeat;
width: 145px;
height: 126px;
position: relative;
}
.icon {
position: absolute;
width: 30px;
height: 30px;
border-radius: 100%;
z-index: 2;
}
.icon1 {
background: green;
top: 20%;
right: 10%;
}
.icon2 {
background: red;
bottom: 10%;
left: 10%;
}
HTML
<div class="container">
<div class="icon icon1"></div>
<div class="icon icon2"></div>
</div>
Here is an example on jsFiddle http://jsfiddle.net/j5cgt22z/
So each icon is positioned inside the container, the planets need to use position:absolute to float them around in the container space but the container needs to have position:relative so they are positioned in relation to their parent http://css-tricks.com/absolute-positioning-inside-relative-positioning/
You can then use z-index on each position:absolute icon to stack each icon so the higher the z-index higher up the stack.
Hope this helps
After realising that there is no general solution for the problem yet. (object-fit isn't widely support).
I used the jquery-Plugin imagefill.js.
CSS
.background {
width:100%;
height:100%;
top: 0;
left: 0;
background-image: url(http://connect.homes.com/wp-content/uploads/2012/05/200392710-0012.jpg);
background-size: cover;
z-index: 0;
position: absolute;
background-position: center center;
}
.container_icons
{
position: absolute;
height: 100%;
width: 100%;
}
.test
{
position: absolute;
background-image: url('http://www.clipartbest.com/cliparts/ncX/qyL/ncXqyLdcB.png');
background-size: 70px auto;
background-repeat: no-repeat;
background-position: 17% 49%;
}
HTML
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/2.1.0/jquery.imagesloaded.min.js"></script>
<script src="http://johnpolacek.github.io/imagefill.js/js/jquery-imagefill.js"></script>
<div class="background"></div>
<div class="container_icons"><img class="test" src="http://upload.wikimedia.org/wikipedia/commons/8/8c/Transparent.png" width="3869px" height="2574px" /></div>
<script>
$('.container_icons').imagefill();
</script>
Here is a jsfiddle --> It doesn't work as good as on my webpage ;-)