Placing the image at the bottom of the container

I need help positioning the image in the center of div: #two, with the screen of the laptop displayed in div two and the lower body of the laptop in div: #three. Here is an example image of how I want it to look, but I'm struggling to achieve this. https://i.sstatic.net/MjVyK.jpg It should also be responsive so that if I resize the window width and the height of div: #one changes, the image moves accordingly.

Any assistance would be greatly appreciated. Thank you!

body{
    margin: 0;
}
#one{
    background-color: #293462;
    height: 20vw;
    display: grid;
    align-items: end;
}
#two{
    background-color: #216583;
    min-height: 40px;
    width: 100vw;
}
#three{
    background-color: #f76262;
    min-height: 100px;
}
h1{
    margin: 0;
}
ul{
    display: grid;
    grid-template-columns: repeat(5, 1fr);
}
li{
    list-style: none;
    text-align: center;
}
li:nth-child(3){
    grid-column: 4/5;
}
img{
    height: 150px;
    position: absolute;
    left: 50%;
}
<div id="one">
    <div id="two">
        <ul>
            <li><h1>text</h1></li>
            <li><h1>text</h1></li>
            <li><h1>text</h1></li>
            <li><h1>text</h1></li>
        </ul>
    </div>
    <img src="https://imgur.com/n8I8D6E.png" alt="laptop">
</div>
<div id="three"></div>

Answer №1

It seems like you might be complicating things a bit by opting for CSS Grid. You can achieve the desired layout using a combination of flexbox and absolute positioning instead.

Below is your code with the necessary modifications:

body{
    margin: 0;
}
#one{
    background-color: #293462;
    height: 20vw;
}
#two{
    background-color: #216583;
}
#three{
    background-color: #f76262;
    min-height: 100px;
}
ul{
    display: flex;
    justify-content: space-between;
    margin: 0;
    padding: 0;
}
li{
    list-style: none;
    text-align: center;
    position:relative;
    padding: 0 10px;
}
li:nth-child(3){
   min-width: 30%;
    
}
img{
    height: 150px;
    position: absolute;
    bottom:-15px;
    left:50%;
    transform: translateX(-50%);
}
<div id="one"></div>
<div id="two">
        <ul>
            <li><h1>text</h1></li>
            <li><h1>text</h1></li>
            <li><img src="https://imgur.com/n8I8D6E.png" alt="laptop"></li>
            <li><h1>text</h1></li>
            <li><h1>text</h1></li>
        </ul>
    </div>
<div id="three"></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

"Discover the simplicity of customizing Bootstrap 5 with an easy-to-use online tool

When I was using Bootstrap 3, there was a convenient tool that allowed me to customize which features I wanted in the minified CSS/JS files to improve loading time. Now, as I delve into the documentation for Bootstrap 5, I find myself struggling to unders ...

Encountering a persistent GET error in the console while working on a project involving a cocktail API

Programming: const API_URL = "www.mycocktaildb.com/api/json/v1/1/search.php?s="; const $cocktailName = $('#cocktailName'); const $instructions = $('instructions'); const $form = $('form'); const $input = $(`inpu ...

Is there a way to disable auto rotation on a website when accessed from a mobile phone?

My current solution involves the following code: @media (max-height: 480px) and (min-width: 480px) and (max-width: 600px) { html{ -webkit-transform: rotate(-90deg); -moz-transform: rotate(-90deg); -ms-transform: rotate(- ...

Customizing Material-UI elements in React using CSS styling

My goal is to style all the <Chip> elements within a <Grid> that has the class .table-header, but they are not changing their style (I have a <p> that should be colored in red and it works). Why does the styling work for the <p> ele ...

How can I loop the keyframe animation across various elements of an SVG file simultaneously?

After creating an animation using CSS and SVG, I am experiencing different parts of it animating in and out. My goal is to have the animation start from the top once it's finished. There are multiple keyframes involved since I'm animating variou ...

"Unlocking the Power of CK Editor for Maximizing Value and Effectively Managing

I have a form with a field titled Description. I am using CKEditor to pass the value entered into this field and store it in my database. Can someone assist me with this? Below is the code snippet: <div id="descriptionMore" style="margin-bottom:20px; ...

Jquery script to update the background of the parent element when Bootstrap Tabs

Currently, I am exploring ways to come up with a more sophisticated solution. However, my proficiency in jquery is somewhat limited at the moment. I believe there must be a more efficient method to achieve the desired function outlined below. In essence, ...

Trouble with CSS loading due to div in Visual Studio MVC

Currently, I am working with Visual Studio 2013 MVC and have a situation regarding the styling of my navbar in _Layout. The navbar includes a messages dropdown menu that utilizes CSS and JS extensively. Interestingly, when I load the messages as a partial ...

Hover effect for child element not activating CSS3 Transition

I need my list item to activate a css3 transition on its child element .pusher when it is hovered over. I usually achieve this using JS, but I want to try implementing it with css3 transitions. After reading some other questions on SO, I attempted to do it ...

Tips on customizing default Polymer CSS

Currently, the core-toolbar features an indent class that shifts the title to the right by 60px. However, material design guidelines suggest that the margin should actually be 80px (oddly enough, the number 60 is not mentioned in the documentation). I cou ...

Showing a collection of cards within a dynamic container set up in a 3x3 grid layout to start

In an attempt to showcase cards within a responsive container utilizing bootstrap and django, my goal is to create a 3x3 grid layout on extra-large screens with scrollable overflow that adjusts based on device width. Initially, I experimented with wrapping ...

Requesting HTML content from a PHP file using JQuery Ajax callback

For an ajax request, I am entering a name in an input box to search for data from a database. Everything is functioning properly. <script> $(document).ready(function(){ $('input#name-submit').on('click', function() { ...

Using JQuery to properly introduce a script in the body of a webpage

<script> /* adjust #splash-bg height based on #meat element */ $(window).on('load',function(){ var splashbgHeight = $("#meat").css("top"); $("#splash-bg").css("height",splashbgHeight); $(w ...

JavaScript tutorial: Locate a specific word in a file and display the subsequent word

Seeking assistance with a task: I need to open a locally stored server file, search for a specific word, and then print the next word after finding the specified one. I have managed to write code that successfully opens the file, but it currently prints e ...

What is the best way to rearrange images within a grid container?

I apologize for asking numerous questions, but could someone please guide me on how to position an image slightly to the right of center or just 1 inch to the left of center? http://jsfiddle.net/96d7udd7/ Below is the HTML code snippet: <figure class ...

Set styles to child elements of an external component using styled-components

In my Component.tsx file, I am using the following template: import {Foo} from 'external-stuff' <Foo> <p>bar</p> </Foo> The Foo component is designed to accept a className parameter. const Foo = ({className, title}) =& ...

Prevent the hover() effect from affecting all div elements at once

I am aiming to achieve a function where hovering over a div with the "rectangle" class will display another div with the "description" class. Initially, the description div will have a display value of "none", but upon hovering, it should become visible. ...

maintaining the alignment of one div's right boundary with another div's right boundary

---------------------- ----------------------------->edge X | | | | | logo | | dropdown menu ...

Having an issue with HTML and JavaScript where the button won't open when pressed. Any help is appreciated

https://jsbin.com/haluhifuqe/edit?html,js,output I'm facing an issue with my HTML & JavaScript code - when I click the button, it doesn't open. Can anyone help me out? <!DOCTYPE html> <html> <head> <meta charset="utf-8 ...

Remove dynamically created elements from an AngularJS div

Is there a way to remove an item from the criteria list when clicking the delete button? Currently, only the filter is being refreshed and not the tables. Any suggestions on how to resolve this issue? HTML <ul class="list-unstyled"> <l ...