Having difficulty adjusting images and divs with proportional percentages

Seeking to recreate the familiar experience of using a laptop, specifically on Windows Vista, with constrained proportions. The goal is for the laptop image to scale based on screen size and for all elements inside #Screen to adjust accordingly in relation to the screen size.

Currently, the height of .MenuBar is set at 4% which seems appropriate, but I am facing difficulty in positioning the bar at the bottom of #Screen. I initially tried using margin-top:96%, but the current value of 56% is closer to placing the bar at the bottom.

The objective is to scale both the laptop image and its contents based on user's screen size using percentages while ensuring they are centered. Additionally, the screen should appear behind the laptop image as if it has been cut out, and everything within the screen should be relative to the screen itself.

If my explanation above seems confusing, I apologize and appreciate any clarification provided.

View website:

JSFiddle demo: http://jsfiddle.net/JAjMY/

Source Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Untitled Document</title>
        <style>
            html, body {
                margin:0;
                padding:0;
            }

            #Laptop {
                margin:0 auto;
                width:545px;
                height:373px;
                background:url(images/laptop.png) no-repeat;
                z-index:1;
            }
            #Laptop .Screen {
                position:absolute;
                width:395px;
                height:221px;
                margin-top:26px;
                margin-left:75px;
                background:#03F;
                z-index:2;
            }
            #Laptop .MenuBar {
                position:relative;
                width:100%;
                height:4%;
                margin-top:56%;
                background:url(images/Microsoft/Vista/MenuBar.png) repeat-x;
                background-size:100% 100%;
            }
        </style>
    </head>
        <div id="Laptop">
            <div class="Screen">
                <div class="MenuBar">

                </div>
            </div>
        </div>
    <body>
    </body>
</html>

Warm regards, Tim

Answer №1

To start, I recommend implementing a few key steps:

  • Firstly, ensure that the image scales to fit the user's screen by setting the width and height of your body and html elements to 100%. Next, adjust the size of the #Laptop element by specifying a percentage for both the width and height.
  • For proper positioning of the screen, make sure the #Laptop div has a CSS property value of either position: relative or position: absolute. I opted for relative to easily center the laptop using margin: 0 auto.
  • You can then position the screen and its components on the #Laptop using properties like left, top, right, and bottom.

Feel free to explore the jsFiddle I have created for reference:

http://jsfiddle.net/m3ta/y4Exs/

Remember that this approach is just one of many ways to achieve the desired result; there are alternative methods available as well.

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

A step-by-step guide to accessing specific row data in a database

I have been searching for a solution for the past few days and am struggling to figure out how to retrieve data from a specific row in a database when I click on the "View Detail" button on the main page. [s_no is unique] Here is my main page: view.php ...

Attempting to implement an EventListener to alter the navbar upon scrolling, unsuccessful at the moment

Exploring ways to update the navigation bar upon scrolling to shrink its size and modify the color scheme (specifically, transitioning from a transparent background to white and altering font colors). Below is the HTML snippet: /* Defining the overa ...

Is there a way to transform an HTMLCollection into an array without depleting it of its elements?

I've been attempting to transform a collection of 4 divs in HTML into an array, but all my efforts seem to lead to the array becoming void. <div class="container"> <div class="shape" id="one"></div> <div class="sh ...

Clicking on the images will display full page versions

Apologies for not making an attempt just yet, but I'm struggling to locate what I need. Here's the menu structure in question: <div class="overlay-navigation"> <nav role="navigation"> <ul class="test"> & ...

Implementing multi-select checkbox feature in Angular 7 using ng-select

I'm looking to create a function where selecting an item will make the corresponding div appear. For instance, if I choose Crédit bancaire and Compte courant associé, the two corresponding divs should be shown. Check out this example: https://stac ...

"Utilize JavaScript to retrieve and display an image from an input field of type URL

I'm trying to implement a feature where the user can input a URL in my HTML file. Can someone help me with writing JavaScript to fetch an image from the URL entered by the user and load it using JavaScript? <div class="url-container"> <in ...

How to enable multiple selections in a Bootstrap 5 form-select, but restrict users to selecting only one

I am looking to create a modal with a list of options where only one option can be selectable. The default form-select is a dropdown menu that requires an unnecessary click, which I want to avoid. I would like all options to be displayed without the need f ...

"Aligning a button to the right in HTML: Step-by-step

On my website, I have added a popup form for users to input their details. This form includes two buttons - one for saving the information and another for canceling the popup. I would like both buttons to be aligned on the right-hand side of the page. Each ...

CSS directives are not compatible with Internet Explorer 8

I implemented a registration form with CSS rules that highlight error fields with a red border when users submit incorrect or empty data. However, this functionality is not working in Internet Explorer. The red border appears correctly in Firefox and Safar ...

What is the necessity for including "overflow" in the code?

http://www.example.com/css/tryit.asp?filename=trycss_dropdown_navbar The link provided above showcases the practice background of a certain website. In the code on the left side, specifically under the style section, there is a "ul" element where the "ove ...

Arranging various s:select dropdowns for inline display styling

I have a form with three consecutive struts2 tags. Upon rendering the page, the s:select tag is automatically converted to the HTML code at the bottom. The issue arises when I attempt to style the form in order to display these dropdowns horizontally. Unf ...

How to effectively utilize `MutationObserver` for monitoring the properties of an `HTMLElement` instead of focusing on its attributes

By using the MutationObserver.observe() method, I am able to monitor changes in a specific attribute. For instance, if I have a Div element and the attribute value is modified, then the designated callback function will be executed. However, if the propert ...

I find myself struggling to manage my javascript dependencies

Currently, I am utilizing NPM along with various angular packages. As per the tutorial on Basic Grid Part 1 at this link, I am encountering challenges. This is my file directory structure: D:/nodeStuff/uiGrid includes: node_modules uigrid.css uigrid.h ...

Aligning a block of text containing two varying font sizes in the center

I'm attempting to center a paragraph element with a span inside that has a different font size, causing the alignment to be slightly off. Below is the HTML code: <p class="priceWrap"><span class="moneySign">$</span>60000.50</p> ...

HTML: Enhancing User Experience by Updating Page Content Dynamically

Looking for assistance with creating HTML code that will dynamically generate a table on the same page after a user submits a form. Rather than redirecting to a new page with the output values, I want the results to display at the bottom of the current p ...

Retrieve an item from the Ionic Firebase database

My current challenge is retrieving data from the Firebase database. user-service.ts getProfile(){ try {; return this.afDatabse.object(`profile/${this.afAuth.auth.currentUser.uid}`); } catch (e) { console.log(e); } } c ...

Quicker loading times for background images when creating PDFs using wkhtmltopdf

As I work on generating a 5-page PDF from my HTML file using wkhtmltopdf, everything seems to be running smoothly. However, I've encountered an issue when it comes to the time it takes to complete this task, especially when a background image is inclu ...

Can CSS interfere with the execution of the document ready function?

When I have a large CSS file on my page, will my document.ready execution wait for the CSS file to load? <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="large-amount-file.css"> </head ...

Styling Labels with CSS Wildcard

I have been using the free NinjaForms plugin on my WordPress site. The default styling for labels is bold, but I prefer them to be lighter. Currently, I achieve this through CSS by targeting individual field IDs. However, this method becomes tedious when a ...

Issue with the camera functionality in phonegap 3.3.0 API on IOS platform

I am currently in the process of developing an application for iPad that will allow users to capture and store photos. I have encountered some difficulties while using the PhoneGap camera API library, as my code is not generating any errors which makes i ...