-1

I'm trying to create a banner with a blurred background and visible text in front however when I run the code the text ends up being blurred along with the background. I have found various solutions, and none of them worked. Please help me.

.bg-image {
        background-image: url("PHT4.jpg");

        filter: blur(8px);
        -webkit-filter: blur(8px);

        height: 40%;

        background-position: center;
        background-repeat: no-repeat;
        background-size: cover;

      }

      .bg-text {
        background-color: rgb(0,0,0);
        background-color: rgba(0,0,0, 0.4);
        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;
      }
    <body>
    <div class="bg-image"</div>
      <div class="bg-text">
        <h1 style="font-size:50px">Elemental</h1>
      </div>
    </body>
kpie
  • 9,588
  • 5
  • 28
  • 50
  • 4
    This is caused by a typo. A missing > after class="bg-image" – A Haworth Dec 29 '21 at 19:06
  • This is using code from the example here: https://www.w3schools.com/howto/howto_css_blurred_background.asp And yes the missing > is the issue. – kpie Dec 29 '21 at 19:12

3 Answers3

1

try instead use filter property, use:

backdrop-filter: blur();

0

Try giving some images as background.

body, html {
  height: 100%;
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

.bg-image {
  /* The image used */
  background-image: url("https://images.pexels.com/photos/1229861/pexels-photo-1229861.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
  
  /* 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;
}
<body>

<div class="bg-image"></div>

<div class="bg-text">
  <h1 style="font-size:50px">Element</h1>
</div>

</body>
lakshna S
  • 255
  • 1
  • 5
-2

Works fine if you add the > after class="bg-image". as A Haworth pointed out in the comments.

.bg-image {
        background-image: url("PHT4.jpg");

        filter: blur(8px);
        -webkit-filter: blur(8px);

        height: 40%;

        background-position: center;
        background-repeat: no-repeat;
        background-size: cover;

      }

      .bg-text {
        background-color: rgb(0,0,0);
        background-color: rgba(0,0,0, 0.4);
        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;
      }
    <body>
    <div class="bg-image"></div>
      <div class="bg-text">
        <h1 style="font-size:50px">Elemental</h1>
      </div>
    </body>
kpie
  • 9,588
  • 5
  • 28
  • 50