2

I have 2 question and hope you can help me.

  1. In the screenshot I have attached you can see that there is a person on the left side and some text on the right side. There is a clean transition from image to text. This site from which I got this, is using visual composer. (https://haartransplantation-vergleich.de/chancen/)

    But how is this made by self-coding?

  2. So I want to create something like this as well but I ONLY want the image-background be blurred out a little bit. The text should be readable. How can this be achieved? I've tried something with "before/after" but hasn't worked for me.

Looking forward to hearing from you guys. Hope someone can share some code as well, if possible because I don't know how to create such a call-to-action box with background img blurred.

enter image description here

Chris W.
  • 22,835
  • 3
  • 60
  • 94
newbie
  • 21
  • 2
  • 1
    Does this answer your question? [Use css gradient over background image](https://stackoverflow.com/questions/16589519/use-css-gradient-over-background-image) – Chris W. Nov 10 '20 at 20:01
  • 1
    Hi! Welcome to SO! The effect you're after is just using a horizontal gradient in css to make that effect. I've linked an example of sorts to get you started and there's numerous tutorials out on the web to reproduce it. Give it a try and tinker a bit then come on back if you run into issues in your attempt. Happy coding! – Chris W. Nov 10 '20 at 20:03

2 Answers2

0
  • It's a CSS gradient
  • applied to a :before pseudo-element
  • which is styled to fill the full height & width of its "parent" element

Screenshot from Chrome's Web Inspector

This was easy to discover using Inspect Element in Chrome, and looking at the relevant CSS for that element.

Pseudoelements are "enabled" or "created" in CSS (as opposed to regular elements which are written in HTML), simply by writing a selector like this:

/* style HTML element */

.person-grad {
  position: relative; /* provide positioning context */
}


/* create pseudoelement */

.person-grad:before {
  /* property required for the pseudoelement to appear */
  content: '';

  /* make the pseudo-element match the dimensions of the "parent" element */
  display: block;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;

  /* more properties, including background gradient... */
}
simmer
  • 2,639
  • 1
  • 18
  • 22
  • hi. thanks for commenting. how do I use this pseudo element? "which is styled to fill the full height & width of its parent element" what does this mean? – newbie Nov 12 '20 at 22:10
  • [Here's a good intro to pseudo-elements](https://blog.logrocket.com/a-guide-to-css-pseudo-elements/). They're "pseudo" elements because they're created via CSS, rather in HTML. I'll update my answer with more context. – simmer Nov 13 '20 at 23:10
0

You can achieve this effect using linier gradients over your images. An easy way to do this is to build a div with a background image, then place a div with your content within that div. This can be done like so:

<div class="blur">
  <div class="content">
    Content Here
  </div>
</div>

To setup the "Blur" you need to layer your background image below a gradient.

.blur {
  background: linear-gradient(90deg, rgba(0,0,0,0) 0%, #fff 50%), url('yourImage.png') no-repeat;
}

The 50% portion is where the gradient will begin to feather, adjust this based on your image used.

I went ahead and made a mockup for you HERE

DrCustUmz
  • 77
  • 7
  • perfect!!! thank you very much!! But what I want to know is : The background-img is not taking it's whole height. How can I achieve, that the the box is taking the full height of my background-img so that my img is not cut or limited by it's box, for which it is used as a background. – newbie Nov 12 '20 at 22:13
  • Also I still don't know how to just blur out the background-img without affecting the text. opactiy is not working here unfortunately. – newbie Nov 12 '20 at 22:16
  • `background-size:auto 100%;` added to the css should do this for you, auto defines the width of the image while 100% defines the height. I have updated the pen here: https://codepen.io/-GiR/pen/jOrXeGR. If this solves this for you please use the check mark ;) – DrCustUmz Nov 12 '20 at 22:18
  • You build within the div the content you want, it does not blur your content. I have added a comment in the pen, but look at the example to understand. – DrCustUmz Nov 12 '20 at 22:26
  • Hi. I didn't get your second comment. So when I add opacity: 0.2 everything including the content is getting blurred. But how can I just blur the image? Thanks so far for your help!!! – newbie Nov 13 '20 at 16:09
  • Your question has been answered, I have even went to the lengths of providing a perfectly working example. If you have another issue post another question or hire a developer to create exactly what you are looking for. As for the question in the original post it has been solved. This is not a forum to continue on with additional issues. – DrCustUmz Nov 13 '20 at 18:10
  • thanks for the reply. But no my questions was only partially answered. Question 2 is still missing. I am trying to find a solution for that. Thanks for the codesample you've provided – newbie Nov 13 '20 at 20:05
  • if you look at the sample it provides everything you need. build your content within the div I even added a comment of where you would put your content. – DrCustUmz Nov 13 '20 at 20:51