Accurately aligning a distorted backdrop image

I'm currently working on a design for a profile page where the header background is a blurred version of the profile picture. However, I am facing some difficulties with the overlay in my implementation.

You can see an example of what I'm talking about here: jsbin

The problem lies in the fact that I can't seem to make the background overlay stop at the white border line as intended. The element '.bg img' seems to be taking the height and width of the body element instead of being limited to 100% of the div.profile-header element. Why is this happening?

CSS:

.profile-header {
  display: block;
  text-align: center;
  border-bottom: #fff 1px solid;

  .bg {
    position: fixed;
    z-index: -1; 
    width: 100%; 
    height: 100%;
    opacity: 0.7;

    img {
      position: absolute;
      height: 100%;
      width: 100%;
      top: 0;
      bottom: 0;
      right: 0;
      left: 0;
      -webkit-filter: blur(15px);
      -moz-filter: blur(15px);
      -o-filter: blur(15px);
      -ms-filter: blur(15px);
      filter: blur(15px);
    }
  }

  .profile-content {
    z-index: 1;
  }

  .profile-img {
    padding: 30px 5px;
    display: block;

    img {
      max-width: 150px;
      margin: 0 auto;
      border-radius: 50%;
    }
  }
}

HTML:

<body>
  <div class="profile-header">
    <div class="bg"> <img src="http://www.twoorist.com/resources/images/uploads/images/97714346f8b6a5c10d716643eee28a8e.jpg"></div>
    <div class="profile-content">
      <div class="profile-img">
        <img src="http://www.twoorist.com/resources/images/uploads/images/97714346f8b6a5c10d716643eee28a8e.jpg">
      </div>
      <div class="header-content">
        <h2>John Doe</h2>
      </div>
    </div>
  </div>
  <p>Some content down here.</p>
</body>

Answer №1

To improve the layout, focus on refining your position attributes.

.header-section {
    position: relative;
}
.header-section .background {
    position: absolute;

    /* use overflow to crop any blurred edges above the white line */
    overflow: hidden; 
}

The positioning of the .background div will now be based on the .header-section div (which adjusts to its content height), as opposed to being relative to the entire page height.

View an example implementation here:

http://jsbin.com/sajazoyiva/1/edit?html,css,output

https://i.sstatic.net/th3q7.png

Answer №2

I made some adjustments to the layout, avoiding the use of position:fixed. The key was applying overflow hidden on the parent element.

Check out the Codepen Demo

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  text-align: center;
  background: lightgrey;
}
.profile-header {
  border: 1px solid grey;
  position: relative;
}
.bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.bg img {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: auto;
  z-index: -1;
  -webkit-filter: blur(10px) sepia(100%) hue-rotate(50deg);
  filter: blur(5px) sepia(100%) hue-rotate(50deg);
}
.profile-img img {
  border-radius: 50%;
}
<div class="profile-header">

  <div class="bg">
    <img src="http://www.twoorist.com/resources/images/uploads/images/97714346f8b6a5c10d716643eee28a8e.jpg">
  </div>

  <div class="profile-content">

    <div class="profile-img">
      <img src="http://www.twoorist.com/resources/images/uploads/images/97714346f8b6a5c10d716643eee28a8e.jpg">
    </div>
    <div class="header-content">
      <h2>John Doe</h2>
    </div>
  </div>
</div>

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

Scaling Images using HTML and CSS

Hey there, I'm currently learning web development and running into a bit of trouble with creating responsive images. Can anyone give me some guidance on what changes I should make in the code below? Here's the HTML code: <div class="caro ...

Step-by-step guide on positioning an image to show at the bottom of a div

I am trying to create a div that covers 100% of the screen height, with a table at the top and white space below it for an image. However, when I add the image, it ends up directly under the table instead of at the bottom of the DIV. I have searched on G ...

Adding HTML content to a statically served file using Flask

Seeking assistance from those more experienced in Flask. I am trying to serve a static file and add some HTML content to it, or display the file beneath some text. Is there a method to achieve this, or am I approaching it incorrectly? @app.route('/com ...

In what scenarios would you choose to use "class" instead of "id"?

I am currently utilizing Bootstrap to style my table, which serves as a basic to-do list. My intention is to insert a form input into one cell and place a check button in the cell adjacent to it on the right side. To achieve this, I plan to utilize id="che ...

Tips for incorporating a CSS class representing an image into a CodeIgniter form submission

<?php $data = array( 'class' => "btn btn-primary btn-lg", 'name' => 'report' ); echo '<span class="glyphicon glyphicon-exclamation-sign"></span> '; echo form_subm ...

Guide to incorporating text with a hover overlay image using HTML, CSS, and JavaScript exclusively

Here is some code for displaying hidden information on shape hover, but there are a couple of issues: 1. When the font size is reduced to 24px, the dark grey background does not cover the entire shape. 2. I want to include text that appears with the hover ...

Creating a Cross Fade Animation effect with the combination of CSS and JavaScript

I've been attempting to create a similar animation using html and css. Below gif shows the desired outcome I am aiming for: https://i.sstatic.net/YsNGy.gif Although I have tried the following code, I have not been able to achieve the desired result ...

PHP pagination restricts the amount of data shown on a page without carrying over to the next page

Welcome to my PHP website! It's designed to showcase data from a database with a simple search feature on the homepage. When a user searches for a keyword, they are directed to a page displaying the relevant data. Below is the code I've implement ...

Disallowing the vertical resizing of a window beyond a specific point

I'm using bootstrap to build my website. One thing I'd like to achieve is preventing the window from resizing beyond a certain point downwards. Currently, here's what I have: html, body{ min-width: 300px; max-width: 3000px; min-height: ...

What is the method to alter text color within a navigation bar?

I used one of the recommended bootstrap 4 navbar styles in my project, but encountered an issue when changing the background color from dark to white. This change made the text inside the navbar invisible. Despite trying various methods to change the text ...

Issue with uppercase letters within a text input field

Imagine having an <input> and a <textarea> along with some JavaScript code that sends the value of the <input> to the <textarea> with additional text. How can you achieve this task? The text-transform: capitalize property is set in ...

Is there a way to change the domain for all relative URLs on an HTML page to a different one that is not its current domain, including in HTML elements and JavaScript HTTP Requests?

I am dealing with a situation where my page contains "domain relative URLs" like ../file/foo or /file/foo within a href attributes, img src attributes, video, audio, web components, js ajax calls, etc. The issue arises when these URLs need to be relative ...

The footer fails to remain at the bottom of the page when there is limited content available

Despite searching extensively on Google, I have not been able to find a solution to this frequently asked question. My challenge is to consistently position the footer at the bottom of the page, even when there is minimal content present. Below is an exce ...

Using Javascript to retrieve the childNode

I have encountered a challenge that I am struggling to overcome. My issue involves utilizing a dynamically generated table with 4 columns: a checkbox, text values, and a hidden input. echo "<tr><td><div class='input-containerh'> ...

After several interactions, the CSS files fail to load

I'm currently utilizing jQuery Mobile with 3 pages, and I've noticed that after navigating between the pages, the CSS is not being rendered properly. LoadCss.js $(document).on("pageinit",function(event) { $("#categoriesPage").on('pages ...

Prevent users from selecting dates in the future using the Bootstrap datepicker

One issue I am facing is how to prevent users from selecting future dates in a form with date input. Here's the solution I came up with: $(document).ready(function(){ $('.month').datepicker({ format: 'yyyy-mm-dd', ...

Utilizing CSS to dynamically update SVG icons within the navigation menu upon tab selection

Feeling frustrated and in need of assistance with my current issue. I am attempting to make a change - when I click on a tab in the menu, the default black SVG icon should be replaced by a white one. #menu a .main-menu-icon { display:inline-block; width:2 ...

What is the limit of CSS includes that IE can process?

While working on theming Drupal, I encountered an unusual issue. After enabling a few modules that added 5 to 10 link tags to the page, I noticed a strange behavior in different browsers. Firefox successfully added the new stylesheets to the cascade, but i ...

Tips for capturing and storing video with HTML5 WebRTC

Before reading the description, make sure to run the code snippet first. This will provide you with a better understanding of the structure. In the 2nd video element, I am trying to record, play, and save video. The issue I'm encountering is that the ...

I'm having trouble displaying my background image unless I specifically set the height in pixels or viewport height

I have been working with ReactJS and on my main page container, I am setting a background image like this: .opening-container { background-image: url("../../images/sadaqashdbg.png"); background-position: center; background-size: cover; ba ...