Embed one div within another div in a flexible layout design

I am working on a design where I need to place a div (profile picture) inside another div (profile banner) in a way that the profile picture is slightly outside of the outer div. This may sound complicated, but I only need it to display this way on desktop - mobile and tablet views can be different.

Here is an example image of what I am aiming for: https://i.sstatic.net/8V6ev.png

My goal is to create a responsive layout with a div inside another div, where the inner div extends slightly beyond the outer div. It needs to be responsive to accommodate varying screen resolutions.

I must admit that this is more of a request rather than an answer, as I am unsure how to achieve this myself.

Answer №1

To position the inner div properly, ensure you use position:absolute; for the inner div and position:relative; for the outside div. To place text after the profile picture within the parent box, add padding left to the parent box. Check out the DEMO for a visual example.

.user-info{
  background:#444;
  position:relative;
  width:100%;
  height:200px;
  box-sizing:border-box;
  padding:16px 16px 16px 216px;
  color:#FFF;
  font-size:32px;
  }
  .profile-picture{
    background:#444;
    width:150px;
    height:150px;
    position:absolute;
    border:2px solid #FFF;
    left:50px;
    bottom:-50px;
    color:#FFF;
    text-align:center;
  }
<div class="user-info">
  <div class="profile-picture">Profile Picture</div>
  
  User Information
</div>

If you wish to make the design responsive, consider using media queries. Resize to see how it adjusts by checking out the DEMO.

Answer №2

Check out this Codepen demonstration:

http://codepen.io/anon/pen/dpgXqp

* {
  transition: .5s all ease-in-out;
  -webkit-transition: .5s all ease-in-out;
  -moz-transition: .5s all ease-in-out;
  -ms-transition: .5s all ease-in-out;
  -o-transition: .5s all ease-in-out;
}
.propic {
  border: 2px solid #e2e2e2;
  margin-top: -130px;
  margin-left: 70px;
}
.cover {
  border: 2px solid #e2e2e2;
  margin-left: 50px;
  margin-top: 20px;
}
.propic:hover,
.cover:hover {
  box-shadow: 0 0 10px 10px #9f9f9f;
  -webkit-box-shadow: 0 0 10px 10px #9f9f9f;
  -moz-box-shadow: 0 0 10px 10px #9f9f9f;
  -ms-box-shadow: 0 0 10px 10px #9f9f9f;
  -o-box-shadow: 0 0 10px 10px #9f9f9f;
}
<img src="http://4.bp.blogspot.com/-2UPJD5hegLs/UR4MlzkGTUI/AAAAAAAAAWk/xpff536gpIQ/s1600/mycover.jpg" alt="Cover_Photo" class="cover" />
<br />
<img src="http://4.bp.blogspot.com/-b3Ty2n3mrOc/UR4MAXUXHDI/AAAAAAAAAWQ/CS31CdrnNY8/s1600/profp.jpg" class="propic" alt="Profile_picture" />

Find the live demo on Codepen here:

http://codepen.io/anon/pen/dpgXqp

Answer №3

.wrapper{
    width: 400px;
    height:200px;
    background-color:red;
}
.box{
position: absolute;
    left: 100px;
    top: 150px;
    width:300px;
    height:200px;
    background-color: green;
}
<div class="wrapper">
   
</div>
 <div class="box">
    </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

Experiencing difficulties with retrieving form data in req.body using Express and node.js

I am facing an issue while trying to create a registration form for new users with profile picture upload. Despite adding body-parser middleware, the form data is not passing correctly to the route and I cannot identify the reason behind it. Error: D:&bso ...

What benefits does utilizing unordered lists provide in navigation bars?

Throughout my research, I have come across numerous tutorials detailing the process of creating a navigation bar. They often begin by adding an unordered list and then proceed to remove the default styling such as bullet points and margins from both the ...

Vuetify's scrolling list feature allows for smooth navigation through a list

Check out my Vuetify code snippet that utilizes a list: <v-list> <v-list-tile v-for="user in users" :key="user.id" avatar @click="" > <v-list-tile-content> < ...

MySQL Entry Update Failure

This is the HTML/EJS code snippet: <div class="Edit-Panel" style="display: none;"> <div class="Edit-Wrapper"> <div class="Editing"> <p class="Edit-Header ...

Issues with PHP Code for Displaying Profile Images

I am facing an issue with displaying users' profile picture on my website. I have written the code, but it seems to be not functioning properly. Can anyone provide me with insights on what might be causing this problem? Here is the snippet of the code ...

Unable to interact with web element

When using selenium, I have a web element that I want to select. The WebElement.IsDisplayed() method returns true, but I am unable to perform the webelement.click() operation. port_dimension = canvas.find( By.xpath( "//*[local-name() = 'rect'][ ...

Removing focus in Meterial-UI [Select] component when clicked outside: Techniques and solutions

Looking to create a simple multiple select feature with Material-UI's Select component. One issue I have encountered is that when deselecting an option or clicking outside the dropdown, the label remains focused until clicked on again or another compo ...

Having trouble with CSS messing up your gridview button display?

Oddly enough, whenever I place buttons inside a gridview, they end up looking very small (as shown in the image below), even though the gridview itself has no CSS applied to it. Is it possible that some other CSS is affecting the buttons? I have too much ...

AngularJS textbox failing to recognize line breaks as expected

I am struggling with the following HTML code: <div class="form-group"> <div class="input-group col-sm-12"> <label for="" class="control-label">Comments</label> ...

Unique ideas for organizing the layout and loading of content on my website

Last year, I created a fan site dedicated to a popular PC game, but now I feel like it could use some improvements. Currently, all the pages on my site share a common header and footer, with only the main content area changing from page to page. My curren ...

Revamping Slideshows: Bringing CSS Animation to JavaScript

/* JavaScript */ var slides=0; var array=new Array('background.jpg','banner.jpg','image.jpg'); var length=array.length-1; $(document).ready( function(){ setInterval(function(){ slides++; ...

Tips for achieving a static background image while allowing scrolling on a webpage in asp.net

I am struggling to implement this on my website. The background image needs to be fixed while the content of the webpage should scroll in asp.net <head runat="server"> <title></title> <style type="text/css"> body { backgr ...

Styling is not being applied to the DataTable when it is invoked through an ajax

I have developed a simple SpringBoot application using Spring Initializer, JPA, embedded Tomcat, Thymeleaf template engine, and packaged it as an executable JAR file. Within this application, I have implemented two datatables: one utilizing ajax and the ot ...

How is it possible for flex-direction to function correctly even when display: flex is not explicitly defined

I'm unsure if it is required to specify the display property when the flex-direction is set in a container. Everything seems to be working fine without it, but I'm concerned that I might be causing issues: .App { background-color: white; ...

Steps to update the action attribute in a form element upon clicking a button

Within the following code snippet, there are 3 buttons - update, back, and delete. Depending on which button is clicked, the $page variable should be assigned to the action attribute in the form element, with the posted data being sent accordingly. <f ...

What is the process for converting HTML assets into a SCORM package?

**css styles fonts images media menu1_images menu2_images menu3_images menu4_images** index.html index_custom.js index_actions.js menu1.html menu1_custom.js menu1_actions.js menu2.html menu2_custom.js menu2_actions.js menu3.html menu3_custom.js menu3_actio ...

Having trouble sending correct true/false values for selected radio buttons on an Angular5 table, often requiring users to click them twice to submit the appropriate values

My goal is to assign true or false values to selected radio buttons in each row and then form an object for submission. To distinguish between the radio button values in each row, I have used {{k}}+{{sizeobj.rbSelected}} as the value which is causing issue ...

Steps for adding a navbar that slides horizontally and overlaps other links on a webpage

I am attempting to design a sliding navigation menu using JQuery. The concept involves having multiple main sections, each with several subsections. When a user hovers over a section, the subsections will expand horizontally. If another section is current ...

How can floats be used to implement margin on a container using CSS?

I've been struggling with this issue for a long time and have yet to find a satisfactory solution, so I've decided to seek help. HTML <section class="cols-2"> <div class="wrapper"> Lorem ipsum dolor sit amet, con ...

My body's padding-right is being altered by Bootstarp/CSS Popup

This is the padding for my body content. https://i.sstatic.net/LG7IE.png <div class="modal fade" id="exampleModal2" tabindex="-1" aria-labelledby="exampleModal2Label" aria-hidden="true" style="padd ...