The background image is functioning correctly, but there seems to be an issue with the image overlay

I attempted to design a profile page for my website users to have an image as a banner and their profile photo. I have achieved this:

https://i.sstatic.net/kFlrQ.jpg

However, when I apply the top-margin to the image, it both moves the image and expands the background, which is not the desired effect. I am aiming for this instead:

https://i.sstatic.net/Va5Wu.jpg

Upon reviewing my code, I noticed that the image appears to be repeated instead of simply fitting/cropping. Here is the code:

class Profiles extends React.Component{

    render(){
        return(
            <div className="profile-container">
                <div className="profile-header" 
                    style={{ backgroundImage: `url(${UserProfile.User1.values.profileHeaderImag})`}}>
                        <img 
                        src={UserProfile.User1.values.profileImg} 
                        alt="profileImg"
                        className="profile-header-image-user"/>                    
                </div>
                <div className="profile-content">
                    <p> more</p>
                </div>
            </div>
        )
    }   
}

and css

.profile-container {
        margin-top: 3rem;
        margin-bottom:5rem;

}

.profile-header {
    width: 70% ;
    height: 5% ;
    max-height: 25rem;
    margin-left: auto;
    margin-right: auto;
    background-color: blue;
    border-radius: 20px;
}


.profile-header-image-user {
    border-radius: 150px;
    width: 130px;
    height: 130px;
    margin-left: 5%;
    margin-top: 15%;
}

.profile-content {
    width: 60%;
    background-color: green;
    margin-left: auto;
    margin-right: auto;
}

My aim is to display the banner and profile pic as illustrated in the second image and maintain this layout when the screen size changes. Any suggestions on how to move the profile pic without affecting the size of the banner?

Thank you!

Answer №1

To achieve the desired layout, ensure that the parent element has a position:relative property, and the child element (profile pic) has a position:absolute property. This way, you can easily adjust the positioning using properties like top, left, right, or bottom. One way to do this is by using the transform: translateY(50%) property, or alternatively, you can use

bottom:-50px; box-sizing:border-box
.

.banner {
  position: relative;
  height: 200px;
  width: 100%;
  background: url("https://i.imgur.com/T8YRjiQ.jpeg");
  background-size: 100% 100%;
  margin-bottom: 55px;
  border-radius: 10px;
  box-shadow: 5px 5px 10px #222;
  border: 5px solid silver;
  box-sizing: border-box;
}

.profile {
  position: absolute;
  height: 156px;
  width: 156px;
  border: 5px solid silver;
  border-radius: 50%;
  bottom: 0;
  left: 50px;
  transform: translateY(50%);
  box-shadow: inherit;
}
<div class="banner">

  <img class="profile" src="https://i.imgur.com/LxxvbbL.png" />

</div>

Answer №2

Consider utilizing absolute positioning:

.user-profile { position: absolute }
.user-profile img { top: 200px; left: '200px; }

Answer №3

To customize the layout of your banner, try using the CSS property position:absolute; for the overall positioning and position:relative; for the profile section. Within the profile section, you can adjust the placement of the picture by experimenting with values for top:5px and left:20px, as well as exploring options for bottom and right alignments.

Answer №4

Implementing position attributes for a profile header.

.profile-header {
    position: relative;
    width: 70% ;
    height: 5% ;
    max-height: 25rem;
    margin-left: auto;
    margin-right: auto;
    background-color: blue;
    border-radius: 20px;
}

.profile-header-image-user {
    position: absolute;
    border-radius: 150px;
    width: 130px;
    height: 130px;
    left: 5%;
    top: 15%;
}

I haven't run any tests yet, but I believe this approach looks promising.

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

Error: The gulp-cssmin plugin encountered a TypeError because it attempted to read the property '0' of a null

I am attempting to condense my code, but I am encountering this error: D:\gulp-compiler\node_modules\gulp-cssmin\node_modules\clean-css\lib\selectors\extractor.js:66 return name.replace(/^\-\w+\-/, ...

Which comment widget/platform does 9GAG utilize?

I am in the process of developing a new website and I am looking for a comment system to use. The comment system that 9GAG is currently using really catches my eye. Take a look at this random post as an example: Despite searching through their source code ...

Items within a shared container are currently displaying stacked on top of each other

I am facing an issue with my bike images and manufacturer names appearing on top of each other instead of next to each other. Despite using "col-md-12", the grid columns are not aligning horizontally as expected. How can I adjust the code so that each imag ...

When working with the Google Sheets API, an error occurred: "this.http.put(...).map is not a valid

Having difficulty with a straightforward request to the Google Sheets API using the PUT method. I followed the syntax for http.put, but an error keeps popping up: this.http.put(...).map is not a function. Here's my code snippet: return this.http ...

What is the process for transferring data (BLOB datatype) to a different table?

I need assistance with transferring data from one blob to another table in the same data type blob. However, I encountered an error message regarding SQL syntax: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB serv ...

Tips for eliminating the vertical line in the material ui permanent drawer

Looking for advice on how to eliminate the vertical line from material-UI's permanent drawer. Any helpful suggestions would be appreciated! ...

Using async/await in a POST handler within Express.js

My goal is to invoke an async function within a POST handler. The async function I'm trying to call looks like this (the code is functional): const seaport = require("./seaport.js"); // This function creates a fixed price sell order (FPSO) ...

Create movement in line art using the position of the cursor

I have created a skull lineart in illustrator and I am trying to make the lines fill in or erase based on mouse position. There are two possible ways to achieve this: Using lazy line painter to draw the lines and then finding a way to animate based on ...

Troubleshooting a jQuery filter function selector issue

Here's a function I've created: $.fn.filterByClass = function(cls) { var o = $(this); return o.filter(function() { if ($(this).attr("class") == cls) { return $(this); } }); }; Let's say we have multiple fo ...

Determining the specific page or method being called in a JSP page upon submission

There is a JSP page named X.JSP that contains radio buttons and a submit button. When the submit button is clicked on X.JSP, the next page Y.JSP is displayed with parameters xxxx=1111&yyyy=2222&zzzz=3333. Is there a way to determine the page, ser ...

Tips for keeping a link in place on an image

Trying to place a link on a 1920x1080 picture and keep it fixed in one spot, regardless of browser size. Any suggestions? <!DOCTYPE html> <link rel="stylesheet" href="../style.css" /> <html> <head> ...

Can a phone without GPS capability still perform geocoding functions?

Is it possible to obtain the location through visiting a website? I am aware that HTML5 allows for this, but will it be compatible with mobile phones? ...

PHP appears to be failing to gather input values from form submissions using both the POST and GET methods

I have been working on setting up a login and logout system, but I am encountering an issue with sending a hidden value for logging out. Despite trying different approaches to solve this problem, I either receive error messages (while the code actually wor ...

Creating a dynamic table in VuetifyJS by populating it with data in real-time

Dealing with a dynamically changing table columns can be tricky. This means that hardcoding the template for the table like this example won't work: <template> <v-data-table :headers="headers" :items="items" hide-actions cl ...

Implementing AngularJS JQuery Datatables Directive for Displaying Multiple Data Tables within a Single View

I have successfully implemented the following directive: angular.module('myApp').directive('jqdatatable', function () { return { restrict: 'A', link: function (scope, element, attrs, ngModelCtrl) { ...

Transforming a Java Array or Collection into a JSON array

After running my Java code, the returned Collection (ArrayList) produces JSON through JAXB that looks like: {"todo":[{"name":"CAMPBELL","sales":"3","time":"1331662363931"}, {"name":"FRESNO","sales":"2","time":"1331662363931"}]} However, I am wondering if ...

Is there a way to reverse the animation playback in Angular?

I am working on an animation that involves a box fading from its original color to yellow. However, I would like to achieve the opposite effect: when the page loads, I want the box to start off as yellow and then fade back to its original color. The challe ...

YouTube videos cannot be embedded using an iframe on Firefox

I inserted a YouTube iframe code inside a div element. <div id="box"> <iframe width="300" height="315" src="//www.youtube.com/embed/82fn4mcNGJY" frameborder="0" allowfullscreen></iframe> </div> After applying CSS to sc ...

What are some methods for creating a responsive table design?

Here is my table that needs to be made responsive: <table style="width:100%" class="table table-hover"> <tr> <th>Booking Date</th> <th>Booking Id</th> ...

Changing Table Cell Color with Bootstrap Based on Value

I have implemented Bootstrap tables into my project using the tables provided on this website Bootstrap Tables and I am populating data from my MongoDB to these tables. One of the fields in my table is labeled "ACTIVE" and I am looking for a way to dynami ...