Fluent Design System CSS - improvement - html

I found this Post CSS-only Acrylic Material from Fluent Design System which is great but it has a big problem.
When I try to use more then one background image it doesn´t work anymore, because the following piece of code is needed:
body, .acrylic::before {
background: url("img1.jpg") center/cover;
background-attachment: fixed;
}
But I want to use different background-images for page sections:
body {
background: #FFF;
}
.hero {
background-image: url(img1.jpg);
}
.about {
background-image: url(img2.jpg);
}
I need to be able to use Acrylic material effect anywhere on the page, like this:
<body>
<div class="hero">
<h1>I´m a hero</h1>
Scroll down link
</div>
<div id=section class="about"><p>Section has different background image <span class="acrylic">but this content is on the Acrylic Fluent Design surface<span/></p><div/>
</body>
So I need Acrylic surface as a universal design component without the limitations of the original post. If somebody knows how to do it I will really appreciate any help.
Thank you (And sorry for my bad writing - I´m not a native speaker so I hope you understand everything I wrote :))

The original answer to the question you link to states that:
Since we use same background for parent and children, we can club them together ;)
However this is not the case for your scenario, you actually want each element to have its own background, right? If I'm understanding you correctly, then you can remove this part of you css:
body, .acrylic::before {
background: url("img1.jpg") center/cover;
background-attachment: fixed;
}
Then to set the background for each section, plus the section's .acrylic background separately, see below:
main {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
width: 50%;
float: left;
}
.acrylic {
padding: 4em 6em;
position: relative;
overflow: hidden;
}
.acrylic::before {
filter: blur(10px);
content: "";
position: absolute;
left: -10px;
top: -10px;
width: calc(100% + 20px);
height: calc(100% + 20px);
z-index: -1;
}
.acrylic::after {
content: "";
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
z-index: -1;
opacity: 0.35;
border: 1px solid #fff;
background: #fff;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAAAUVBMVEWFhYWDg4N3d3dtbW17e3t1dXWBgYGHh4d5eXlzc3OLi4ubm5uVlZWPj4+NjY19fX2JiYl/f39ra2uRkZGZmZlpaWmXl5dvb29xcXGTk5NnZ2c8TV1mAAAAG3RSTlNAQEBAQEBAQEBAQEBAQEBAQEBAQ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eoSmuOlokqw49pgomjLeh7icHNlG19yjs6XXOMedYm5xH2YxpV2tc0Ro2jJfxC50ApuxGob7lMsxfTbeUv07TyYxpeLucEH1gNd4IKH2LAg5TdVhlCafZvpskfncCfx8pOhJzd76bJWeYFnFciwcYfubRc12Ip/ppIhA1/mSZ/RxjFDrJC5xifFjJpY2Xl5zXdguFqYyTR1zSp1Y9p+tktDYYSNflcxI0iyO4TPBdlRcpeqjK/piF5bklq77VSEaA+z8qmJTFzIWiitbnzR794USKBUaT0NTEsVjZqLaFVqJoPN9ODG70IPbfBHKK+/q/AWR0tJzYHRULOa4MP+W/HfGadZUbfw177G7j/OGbIs8TahLyynl4X4RinF793Oz+BU0saXtUHrVBFT/DnA3ctNPoGbs4hRIjTok8i+algT1lTHi4SxFvONKNrgQFAq2/gFnWMXgwffgYMJpiKYkmW3tTg3ZQ9Jq+f8XN+A5eeUKHWvJWJ2sgJ1Sop+wwhqFVijqWaJhwtD8MNlSBeWNNWTa5Z5kPZw5+LbVT99wqTdx29lMUH4OIG/D86ruKEauBjvH5xy6um/Sfj7ei6UUVk4AIl3MyD4MSSTOFgSwsH/QJWaQ5as7ZcmgBZkzjjU1UrQ74ci1gWBCSGHtuV1H2mhSnO3Wp/3fEV5a+4wz//6qy8JxjZsmxxy5+4w9CDNJY09T072iKG0EnOS0arEYgXqYnXcYHwjTtUNAcMelOd4xpkoqiTYICWFq0JSiPfPDQdnt+4/wuqcXY47QILbgAAAABJRU5ErkJggg==);
}
.shadow {
border-radius: 1px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1), 0 1px 8px rgba(0, 0, 0, 0.2);
}
/* From here down are the changes to the original answer */
.hero,
.about {
position: relative;
z-index: -1;
}
.hero,
.hero .acrylic::before {
background: url("https://images.unsplash.com/photo-1427434991195-f42379e2139d?auto=format&fit=crop&w=1189&q=60&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D") center/cover;
}
.about,
.about .acrylic::before {
background: url("https://images.unsplash.com/photo-1452723312111-3a7d0db0e024?w=700") center/cover;
}
<main class="hero">
<div class="acrylic shadow">
Acrylic material!
</div>
</main>
<main class="about">
<div class="acrylic shadow">
Acrylic material!
</div>
</main>

Could you try this, maybe it works:
hero, .acrylic::before {
background: url("img1.jpg") center/cover;
background-attachment: fixed;
}
about, .acrylic::before {
background: url("img2.jpg") center/cover;
background-attachment: fixed;
}
is it maybe possible that you provide a Screenshot how you wanna have it? :)

Related

Why isn't backdrop-filter: blur() working properly?

I'm trying to implement this image:
Where, a div with text "Dog" is partially covering and blurring the image. So I tried this:
.profile {
background-image: url(https://townofbeekmantown.com/wp-content/uploads/2019/06/2-dog.jpg);
width: 250px;
height: 250px;
background-size: cover;
background-position: 0px;
}
.name {
position: absolute;
bottom: 0px;
left: 0px;
background-color: black;
color: white;
padding-top: 15px;
padding-bottom: 15px;
width: 100%;
opacity: 60%;
backdrop-filter: blur(10px); // should do the trick but not working??
}
<body class="profile">
<div class="name">Dog</div>
</body>
As you can see, although the div has the right color/opacity, it is not blurring the part of the image it covers.
If backdrop-filter is applied on <div class="name"></div>, then shouldn't it take affect on the element behind it (which is <body class="profile">)? I'm confused as to what I am doing wrong. If anyone can point me in the right direction, I would greatly appreciate it. Thanks!
This works for me:
Change <body class="profile"> to something like <div class="profile">.
<body> is a special HTML element.
Remove opacity: 0.6. It makes the entire element translucent which isn't what you want.
Instead, change the background-color to rgba( 0, 0, 0, 0.6 ) - then the backdrop will be partially visible through this semitransparent background.
Also, I replaced width: 100% with right: 0; as width: 100% will be affected by box-sizing: which will trip you up as you work on the textual content of your HTML.
You also need to add position: relative; to .profile so that the .name's position: absolute works.
.profile {
width: 250px;
height: 250px;
position: relative;
background-image: url("https://townofbeekmantown.com/wp-content/uploads/2019/06/2-dog.jpg");
background-size: cover;
background-position: 0px;
}
.name {
position: absolute;
bottom: 0;
left: 0;
right: 0;
padding-top: 15px;
padding-bottom: 15px;
background: rgba( 0, 0, 0, 0.6 );
backdrop-filter: blur(10px);
color: white;
text-align: center;
}
<div>
<div class="profile">
<div class="name">Dog</div>
</div>
</div>
You could set a transparent background using RGBA instead of using opacity to have the blur effect on the background. Also note that you are using an invalid order of HTML code.
The order is as follow:
<html>
<head>
<!-- All meta tags -->
</head>
<body>
<!-- All your elements such as divs, navs etc.. -->
</body>
</html>
So if we take your code, you would have something like this:
background-color: rgba(0,0,0,0.55);
backdrop-filter: blur(10px);
! For the sake of demonstration, I added position: relative to the profile class, this ensures your name element stays inside of the box. Remove that line if you are planning to copy the code below or don't want to have this.
.profile {
background: url(https://townofbeekmantown.com/wp-content/uploads/2019/06/2-dog.jpg);
width: 250px;
height: 250px;
background-size: cover;
background-position: 0px;
position: relative;
}
.name {
position: absolute;
bottom: 0px;
left: 0px;
background-color: rgba(0,0,0,0.55);
color: white;
padding-top: 15px;
padding-bottom: 15px;
width: 100%;
text-align: center;
backdrop-filter: blur(15px); // should do the trick but not working??
}
<div class="profile">
<div class="name">Dog</div>
</div>

How does background-attachment work with its children?

I was looking for how to generate the new glass morphism effect with CSS3. Afortunatelly I found This article that make it happens. In the first method the article makes something like this (I wrote this code with the same structure and properties):
body {
min-height: 100vh;
background: url(./bg.jpg) no-repeat; /*<------ check that I'm using a background image*/
background-size: cover;
display: flex;
align-items: center;
justify-content: center;
background-attachment: fixed; /*<------ This is the most important part*/
}
.contenedor {
width: 500px;
border-radius: 10px;
height: 400px;
border: 1px solid #eee;
position: relative;
overflow: hidden;
background: inherit; /*<------- Here the ".contenedor" element inherits its parent's background*/
z-index: 2;
}
.contenedor::before {
z-index: -1;
content: "";
background: inherit;
position: absolute;
width: 100%;
height: 100%;
box-shadow: inset 0px 0px 2000px rgba(255, 255, 255, 0.5); /*<------- Here the magic happens making a blur inside */
filter: blur(10px);
}
With this HTML:
<body>
<div class="contenedor">
TEXT INSIDE
</div>
</body>
Now, I don't understand how the background-attachment works to mantain the background in the .contenedor element with inherit background.
I know that the background:inherit is to inherit all background properties from its parent, but what happen if I put
{
...
background: url(./bg.jpg) no-repeat; /*<------ check that I'm using a background image*/
background-size: cover;
background-attachment: fixed; /*<------ This is the most important part*/
...
}
instead inherit, It doesn't work.
PDT: Of course I understand the ::before pseudoclass to achieve the background and I'm using the first methos instead the second because is not compatible with Mozilla Firefox
Thank you all and sorry about my poor English

Fade bottom text while scroll to down with linear gradient

I have list of news articles so user know that there is some text in bottom. How i tried like this style="background: linear-gradient(360deg, rgba(135, 135, 135, 0) 0%, #878787 20%)"
but i am not getting what i want to achieve.
Here is screen how i want to get it
Now i am getting like this
Just apply it on an ::after pseudoelement. I create a snippet to illustrate. Create a wrapper with relative and ::after on it, and inside the scroll layer and the articles. Just easy.
.wrapper {
position: relative;
}
.scroll {
position: relative;
height: 150px;
overflow: auto;
}
.article {
height: 80px;
background: blue;
margin: 10px;
}
.wrapper::after {
content: " ";
position: absolute;
bottom: 0;
width: 100%;
z-index: 1111;
background-image: linear-gradient(transparent, #ccc);
height: 50px;
}
<div class="wrapper">
<div class="scroll">
<div class="article">a</div>
<div class="article">b</div>
<div class="article">c</div>
</div>
</div>
You need to just update your .scss file like:
.item-md{
background: #878787;
padding-right:15px !important;
color: #fff !important;
}
I think its solve your problem

Need help getting a background to show through some text in a more complex way than clipping offers

See the attached image for what I am trying to acheive.
Basically I need the background image to come through the text, except where the text overlaps off the faded panel. This needs the text to become the same colour/opactity as the panel itself.
This is giving me a headache but would like to see how far/what solutions could achieve my goal.
Thanks, Harry.
EDIT 1: Here's a codepen if you'd like to test anything https://codepen.io/itsharryfrancis/pen/XVagep
I've tried using this with it but it does
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
EDIT 2: I am going to leave a codepen here that is the latest version of what I have so far for anyone that may want to see it in the future.
https://codepen.io/itsharryfrancis/pen/goxVQP?editors=0100
Here is working example that implements required look, but it uses relatively new clip-path property that is not supported in IE and Edge. This issue can be resolved by using SVG clipping instead (or as fallback), but I hope that this is enough for the start.
.example {
width: 600px;
}
.example {
background: url('http://dummy-images.com/nature/dummy-1024x576-Waterfalls.jpg');
background-position: center center;
background-size: cover;
position: relative;
}
.text {
width: 100%;
font-family: Helvetica, Arial, sans-serif;
font-weight: 300;
font-size: 100px;
line-height: 1.0;
text-transform: uppercase;
}
.part1, .part2 {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 0;
display: flex;
align-items: center;
justify-content: center;
}
.part1:before {
content: '';
position: absolute;
top: 0;
left: 0;
bottom: 0;
width: 400px;
background-color: rgba(255, 255, 255, 0.5);
z-index: 1;
}
.part1 .text {
position: relative;
z-index: 2;
background: url('http://dummy-images.com/nature/dummy-1024x576-Waterfalls.jpg');
background-position: center center;
background-size: 100%;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.part2 {
color: rgba(255, 255, 255, 0.5);
z-index: 3;
clip-path: polygon(400px 0px, 100% 0px, 100% 100%, 400px 100%);
}
<div class="example">
<div class="part1"><span class="text">Stack<br>Overflow</span></div>
<div class="part2"><span class="text">Stack<br>Overflow</span></div>
</div>
UPDATE: I've realized that initial version have misaligned background under text. Updated version fixes this issue, but at a small price: .text elements are required to have width: 100% as it allows to align backgrounds. It will cause a need to add some padding in a case if text should be additionally aligned.

How to make in CSS an overlay over an image?

I am trying to achieve something like this:
When I hover over an image, I would like to put on that image this dark color with some text and the icon.
I am stuck here. I found some tutorials but they didn't work out for this case.
Also, another issue -- every image has a different height. The width is always the same.
How can this effect be achieved?
You can achieve this with this simple CSS/HTML:
.image-container {
position: relative;
width: 200px;
height: 300px;
}
.image-container .after {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: none;
color: #FFF;
}
.image-container:hover .after {
display: block;
background: rgba(0, 0, 0, .6);
}
HTML
<div class="image-container">
<img src="http://lorempixel.com/300/200" />
<div class="after">This is some content</div>
</div>
Demo: http://jsfiddle.net/6Mt3Q/
UPD: Here is one nice final demo with some extra stylings.
.image-container {
position: relative;
display: inline-block;
}
.image-container img {display: block;}
.image-container .after {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: none;
color: #FFF;
}
.image-container:hover .after {
display: block;
background: rgba(0, 0, 0, .6);
}
.image-container .after .content {
position: absolute;
bottom: 0;
font-family: Arial;
text-align: center;
width: 100%;
box-sizing: border-box;
padding: 5px;
}
.image-container .after .zoom {
color: #DDD;
font-size: 48px;
position: absolute;
top: 50%;
left: 50%;
margin: -30px 0 0 -19px;
height: 50px;
width: 45px;
cursor: pointer;
}
.image-container .after .zoom:hover {
color: #FFF;
}
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet"/>
<div class="image-container">
<img src="http://lorempixel.com/300/180" />
<div class="after">
<span class="content">This is some content. It can be long and span several lines.</span>
<span class="zoom">
<i class="fa fa-search"></i>
</span>
</div>
</div>
You could use a pseudo element for this, and have your image on a hover:
.image {
position: relative;
height: 300px;
width: 300px;
background: url(http://lorempixel.com/300/300);
}
.image:before {
content: "";
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
transition: all 0.8s;
opacity: 0;
background: url(http://lorempixel.com/300/200);
background-size: 100% 100%;
}
.image:hover:before {
opacity: 0.8;
}
<div class="image"></div>
Putting this answer here as it is the top result in Google.
If you want a quick and simple way:
filter: brightness(0.2);
*Not compatible with IE
A bit late for this, but this thread comes up in Google as a top result when searching for an overlay method.
You could simply use a background-blend-mode
.foo {
background-image: url(images/image1.png), url(images/image2.png);
background-color: violet;
background-blend-mode: screen multiply;
}
What this does is it takes the second image, and it blends it with the background colour by using the multiply blend mode, and then it blends the first image with the second image and the background colour by using the screen blend mode. There are 16 different blend modes that you could use to achieve any overlay.
multiply, screen, overlay, darken, lighten, color-dodge, color-burn, hard-light, soft-light, difference, exclusion, hue, saturation, color and luminosity.
.bg-img{
text-align: center;
padding: 130px 0px;
width: 100% !important;
background-size: cover !important;
background-repeat: no-repeat !important;
background: linear-gradient(0deg, rgba(0, 0, 0, 0.86), rgba(0, 0, 0, 0.86)), url(your-img-path);
}