Tips for creating blurred background images with CSS

I am experiencing an issue where the background image is being blurred along with the content. Despite trying to adjust the z-index, it seems like it's not working as expected. Below is the HTML code, and I would appreciate a solution with an explanation:

    <!DOCTYPE html>
<html>
<head>
    <title>Student-login</title>
    <link href='http://fonts.googleapis.com/css?family=Shadows+Into+Light' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
    <div class="body">
        <div class="main-form">
            <h1>Student Login</h1>
            <form class="login">
                <input type="text" placeholder="*User name" name="user_name"></input><br>
                <input type="password" placeholder="*Password" name="user_name"></input><br>
                <input type="button" value="Login"></input><br>
                <div class="button"><a href="register.html">Register</a></div>
            </form>
        </div>
    </div>
</body>
</html>

Here is the CSS file:

.body{

            position: absolute;
            top: -20px;
            left: -20px;
            right: -40px;
            bottom: -40px;
            width: auto;
            height: auto;
            background-image: url("background.jpg");
            background-size: cover;
            -webkit-filter: blur(5px);
            filter:blur(5px);
            z-index: 0;
}
h1{
    font-family: 'Shadows Into Light', cursive;
    color: #282828;
    text-align: center;
    margin: 2%;
}
.main-form{
    float: right;
    margin-top: 3%;
    height:auto;
    border-radius: 3px;
    background:#F0F0F0;
    opacity: .6;
    padding-top: 1%;
    padding-left: 4%;
    padding-right: 4%;
    padding-bottom: 1%;
    z-index: 1;
}
.login input[type="text"]{

    width: 260px;
    height: 35px;
    border-radius: 2px;
    border: 1px solid #505050 ;
    background: transparent;
    margin: 2%;
}
.login input[type="text"]:focus{

    border: 1px solid #0033FF;
}

.login input[type="password"]{

    width: 260px;
    height: 35px;
    border-radius: 2px;
    border: 1px solid #505050 ;
    background: transparent;
    margin: 2%;
}
.login input[type="password"]:focus{

    border: 1px solid #0033FF;
}

.login input[type="button"]{

    width: 265px;
    height: 35px;
    border-radius: 2px;
    border: 1px solid #505050 ;
    background: transparent;
    margin: 2%;
    font-family: 'Shadows Into Light', cursive;
    font-size: 100%;
    font-weight: bold;
}
.login input[type="button"]:hover{

    background-color: #404040;
    color: white;
}
.button {

    width: 270px;
    height: 35px;
    border-radius: 2px;
    border: 1px solid #505050 ;
    background: transparent;
    margin: 2%;
    font-family: 'Shadows Into Light', cursive;
    font-size: 100%;
    font-weight: bold;
    text-decoration: none;
    color:black;
    text-align: center;
}
.button a{

    font-family: 'Shadows Into Light', cursive;
    font-size: 100%;
    font-weight: bold;
    text-decoration: none;
    color:black;
    text-align: center;
}
.button:hover{

    background-color: #404040;
}
.button:hover a{

    color: white;
}

.login select{

    width: 265px;
    height: 35px;
    border-radius: 2px;
    border: 1px solid #505050 ;
    background: transparent;
    margin: 2%;
    font-family: 'Shadows Into Light', cursive;
    font-size: 100%;
    font-weight: bold;
}
.login select:hover{

    background-color: #404040;
    color: white;
}
::-webkit-input-placeholder {
   color: red;
}
:-moz-placeholder { /* Firefox 18- */
   color: red;  
}

::-moz-placeholder {  /* Firefox 19+ */
   color: red;  
}

:-ms-input-placeholder {  
   color: red;  
}

Answer №1

One tool that could be useful in visualizing the situation is FireFox's 3Ddomviewer. Essentially, the issue at hand is that the blur effect is being applied to the main-form id because it is a child of the body div where the effect is being implemented. Furthermore, regarding why the z-index is not functioning as expected - the reason lies in understanding that z-index only works on elements with a specified position. Within your main-form div, no position has been set yet. Once you assign a position and adjust the z-index to a significantly negative number, the element will disappear as it gets hidden underneath other stacked elements. Refer to this article for further clarification. Trust this explanation provides some clarity on the matter.

Answer №2

The reason for this is that by specifying -webkit-filter: blur(5px) and filter: blur(5px) in the body selector, you are actually blurring the entire page. To only blur an image, you should target the specific image element like this:

#imageSelector {
    -webkit-transform: blur(5px);
    transform: blur(5px);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Stop automatic page refresh after submitting a jQuery post request

I've tried various solutions, but unfortunately, neither e.preventDefault() nor return false seem to be working for me. When I use prevent default ajax doesn't make post request. Even using $.post doesn't work as expected. Furthermore, addin ...

What causes the inconsistency in width distribution among flex children when the flex grow property is set to 1 alongside text content?

Why do the elements one, two, and damn not take up equal space, as they all have flex: 1? I want them to have equal widths based on the parent's width. How can I adjust it so that the element with class damn takes up less space than the other two? .w ...

I'm wondering why the columns in my Bootstrap 4 grid don't have uniform height and width

Currently, I am utilizing Bootstrap 4 to create a grid view. However, I have encountered an issue where my columns do not have the same width and their heights are uneven, as evident from the borders. It is mentioned that in Bootstrap 4, columns should inh ...

Balancing icons and text to align perfectly in a straight line

https://jsfiddle.net/magnix2k/z1sx03by/1/ My goal is to make sure that the icons in buttons, along with their labels and accompanying text, are perfectly aligned. Despite trying various CSS codes like 'top: 0;', 'padding: 0;', 'di ...

Incorporating Flash videos into an Angular HTML partial using AngularJS techniques

I've been struggling to embed a flash game in an angular HTML partial. The game loads without errors, but when I right click on the blank flash screen, it says "movie not loaded." I have tried using https://github.com/Pleasurazy/angularjs-media and an ...

The appearance of a Kendo dialog box in Angular 2+ inside a Kendo grid is triggered when enclosed within a kendoGridDetail

Is there a CSS method to display the Kendo Dialog outside of the kendo grid when it is wrapped inside kendoGridDetailTemplate? Here's how my component currently appears: <kendo-grid><div *kendoGridDetailTemplate="let dataItem"> <looku ...

Styling various versions of a <button> using Styled Components

In my app, I have a basic colored button that needs to change its color depending on the UI state: const StyledButton = styled.button` & { border: 0; color: white; cursor: pointer; } &:hover { background-color: ${(props) => ...

Incorporate JavaScript code into an Angular UI-Router view

I can't seem to find an answer to this question anywhere, so I'm hoping someone here can help me out. In my AngularJS app, I am using ui-router to load multiple views into the same <ui-view> element. I am trying to implement Jquery UI&apos ...

Angular routing exhibits peculiar behavior with varying browsers

Recently, I completed a web project using AngularJS and Bootstrap with Brackets as my editing tool. Testing was done in Chrome through Brackets acting as the server. Everything worked perfectly on Windows 10 when tested locally or deployed on Tomcat as lon ...

"Optimizing Image Display in Web Browsers

Currently, I am using JavaScript to dynamically size a transparent .gif on my website. The original image size is approximately 200x200 pixels, but it's usually resized to be between 600x600 and 800x800. When viewing the resized image in IE8 and FF3, ...

How can you utilize jQuery to eliminate specific select field values from the DOM prior to submission?

I am currently working on a Squarespace form that utilizes jQuery to show/hide specific fields in order to create a customized form using the show(); and hide(); functions. $(".option2 select").hide(); The issue I am facing is that simply hiding the fiel ...

Align one element vertically at the bottom

I am facing an issue with aligning a single child element to the bottom of a holder div that has fixed dimensions. Currently, I have another element with the same height as the container, which helps in alignment at the bottom. However, when this second el ...

What is preventing the Selenium WebDriver from clicking on elements, despite their presence and focus?

Once again, I am facing a Selenium issue. Last week everything was running smoothly, but today when I attempted to write some new tests, I encountered a strange problem. Every time I try to click on something, Selenium seems to ignore the click. Even wit ...

Using jQuery's toggle function with a double click event to change the display to none

A div I created has the ability to expand to full screen upon double click, and I now wish to implement a toggle function so it can return to its original size when double clicked again. Initially, the code successfully increased the size of the div. Howe ...

Taking data input from three textboxes and storing them in a PHP array

In my HTML form, I have 3 text input fields and one submit button. Each text field is intended for entering the name of an animal, which should then be saved into a PHP array. Here is the structure of my HTML form: <form action="Test.php" method="post ...

Receiving an unexpected value from the input attribute

Currently, I am facing a challenge in retrieving data from another component by using the selector in the HTML file of the parent component. Here is how I implemented it: <app-graphs [module]="module" hidden></app-graphs> In the chi ...

What measures can be taken to stop LESS partials from compiling independently?

When working with LESS, I utilize partials that are included (@include) into the main LESS stylesheet. A common issue I face is that each partial ends up compiling to its own CSS file, leading to project clutter. In SASS, if a file is named with an unders ...

Syntax for retrieving response with jQuery AJAX

Currently, I am in the process of working on an AJAX request that triggers a URL when a specific button is clicked. The fundamental aspects are running smoothly, ensuring that the GET request is activated towards the URL upon button click. I have also cros ...

Ways to create collapsible navigation bars in your website

As someone exploring client-side development, I may be misusing the term "collapsible" in my title. What I aim to accomplish in my web application is allowing users to collapse header bars into small chevrons and expand them back when necessary. I am on t ...

How do I prevent the default submission behavior in an asp:ImageButton when the user presses the enter key in ASP.NET using C#?

Whenever I attempt to use this code snippet, it doesn't seem to work properly. How can I prevent the submit behavior of an asp:ImageButton? Here is the HTML code I am working with: <td class="style101"> <asp:ImageButton ID="imgBtnPos ...