Achieving consistent positioning for an image across resolutions and scales: A foolproof guide

Here is a sample of the div I am working with:

<div id="information">
<a href="https://www.com.edu"><img src="https://com-bb-dev.com.edu/branding/themes/as_2012_orig/images/bbbanner.png" 
style="position: absolute;left: 296px;"></a>
</div>

The issue arises when the monitor resolution is set to 1920x1200, the image appears perfectly aligned. However, when the window is resized or the resolution is changed to lower values, the position of the image shifts. What is the correct method to ensure that an image aligns with an element below it? I have attempted using percentages but it does not seem any different from static pixel values.

For example:

If you want to view the entire page's layout, you can visit . The website is SSL verified.

Current structure of the page:

<div id="information">
<a href="https://www.com.edu"><img src="https://com-bb-dev.com.edu/branding/themes/as_2012_orig/images/bbbanner.png" style="
    position: absolute;
    /* left: 296px; */
    margin-left: 297px;
"></a>

</div>
<div id="loginPageContainer">

  <div id="loginPane">

    <div id="loginContainer">

      <div class="clearfix loginBody">
        <div id="newStu">Students: Your initial log on is your WebAdvisor Username and your password is your seven digit COM ID number. To keep your account secure, please <a href="https://password.com.edu/_layouts/PG/login.aspx?ReturnUrl=%2fdefault.aspx">use this site</a> to change your password at your earliest convenience.</div>
<div id="seeClasses">You will not see your course within your Course List in Blackboard until the official start date (review your class schedule).</div>

CSS styling:

#information {
    height: 60px;
    padding-top: 10px;
    padding-bottom: 10px;
}

#loginPageContainer {
    background: #eaeaea;
    display: table;
    text-align: center;
    width: 100%;
    padding-top: 30px;
    height: 569px;
    zoom: 1;
}

#loginPane {
    vertical-align: top;
    display: inline-block;
    background: white;
    margin-bottom: 3px;
    height: 541px;
    -webkit-box-shadow: 0px 3px 22px 5px rgba(0,0,0,0.75);
    -moz-box-shadow: 0px 3px 22px 5px rgba(0,0,0,0.75);
    box-shadow: 0px 3px 22px 5px rgba(0,0,0,0.75);
}

#loginContainer .loginBody {
    width: 585px;
}

Answer №1

At first, I was ready to respond with a long criticism until I finally understood your question.

1) Avoid using absolute positioning. Instead, consider using a container or repurposing an existing element as a container.

2) Utilizing Bootstrap would be beneficial. Simply surround both elements with <div class="container"> for optimal results.

3) As for your specific situation where there are no container elements inside #information, you could replicate the container from the adjacent section using your logo <a>. If modifying HTML is not an option, implementing media queries may be necessary for achieving consistency across different resolutions. Adding a new container around the problematic sections might be the simplest solution.

If altering the HTML is feasible, provide that information in your question for alternative approaches.

Edit: Assuming modifications can be made to your code and desiring the background colors to extend the viewport's width:

<div id="information">
  <div class="container">
    <a class="logo"></a>
  </div>
</div>
<div id="logingPageContainer">
  <div class="container">
    <div class="pane1"></div>
    <div class="pane2"></div>
  </div>
</div>

This structural adjustment enables CSS styling like:

.pane1, .pane2 { display: block; float: left; width: 50%; /* Adjust as needed or split for individual widths */ } .container { width: 80%; margin: 0 auto; }

These changes should guide you towards the desired outcome. For responsiveness, consider incorporating media queries due to potential challenges with fixed pixel widths in percentage-based layouts. While this provides a foundation, further adjustments within the children of each pane may be required for optimal display on various devices. Remember that static pixels may present issues with percentage widths. Feel free to ask for additional assistance if needed.

Answer №2

Try incorporating the following CSS code:

#loginPane {
  position: absolute;
  left: 10px; //adjust this value as needed for proper alignment.
}

This setup should do the trick.

UPDATE: To place the logo above the panel, use the following script:

<script>
var panePosition = document.getElementById('loginPane').position();
var panepx = panePosition.split(',', 1)[0];
document.getElementById('yourImgId').style.left = panepx + 'px';

Make sure to also include position: absolute; for your logo's styling.

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

Tips for implementing arraybuffer playback in video tags

I have been exploring ways to convert images from an HTML canvas into a video. After much research, I just want to be able to select a few images and turn them into a video. By passing multiple images to a library engine, I am able to receive an array buff ...

I'm having trouble getting the code to work properly after the "else" statement using both jQuery and Javascript. My head is

Being a newcomer to javascript and jquery, debugging and viewing log files seem like a challenge compared to php. Any help from experienced individuals would be greatly appreciated. Although my code mostly works fine, I'm having trouble with the if/e ...

Steps for exporting a module from a JavaScript file that is linked:

When I include the main.js file in my project, the code below works properly: modules.exports = { property: value } However, if I include it in a web page like this: <!DOCTYPE html> <html> <head> <script src="main.js"& ...

How can Angular be used for live search to provide precise search results even when the server does not return data in the expected sequence?

Currently, I am in the process of constructing a website for one of my clients. The search page on the site is designed to update search results as you type in the search bar - with each keystroke triggering a new search request. However, there's an i ...

Troubleshooting a problem with CSS styling in a jQuery bounce effect

In my current project, I am experimenting with creating a unique 'hovering' link. When the user hovers over an image and then moves the mouse away, I want the link to 'jump' back instead of using jQuery animation. +-----------+ | I ...

Tips for showing the value in the subsequent stage of a multi-step form

Assistance is required for the query below: Is there a way to display the input field value from one step to the next in multistep forms? Similar to how Microsoft login shows the email in the next step as depicted in the image below: https://i.sstatic.ne ...

Update the text with jQuery and AJAX

I've written a script using jQuery and AJAX to change my button text from "Approve" to "Approved." However, I'm facing an issue where clicking on one row changes the button text for all rows. Here's the code for my button: <td> & ...

In order for the user to proceed, they must either leave the zip code field blank or input a 5-digit number. However, I am encountering a problem with the else if statement

/* The user must either leave the zip code field blank or input a 5-digit number */ <script> function max(){ /* this function checks the input fields and displays an alert message if a mistake is found */ ...

JQuery button refusing to trigger点击

I've searched high and low on various coding forums but still can't find a solution. My HTML code is as follows: <input type="button" value="Sign Up Here" id="buttonClick"> and I have a script at the top that looks like this: < ...

Switch up the webpage's font using a dropdown selection box

I'm interested in adding a drop-down box to my webpage that allows users to change the font of the site when they click on it. I attempted the code below, but it didn't seem to work. Any suggestions? Regards, Sam CSS .font1 p { font-family: " ...

The video link was not found during the page scraping process

I'm trying to download a video from the page below: After inspecting with Firebug, I found the video url, <video src="https://09-lvl3-pdl.vimeocdn.com/01/1449/2/57246728/138634997.mp4?expires=1457996449&amp;token=089e435c20e7781d36fce" preloa ...

A large responsive bootstrap website filling only half the screen

I am currently in the process of developing a simple version of a Content Management System (CMS). I have created a page that offers an HTML template, allowing users to insert their own text and image uploads to display on another screen. The template fun ...

Choose a Vue filter according to the variable selected

My Current Table Dilemma Creating a table from a 2D array in Vue2 has been successful for me, as I've managed to display all the values correctly. However, I am facing issues with formatting. The template code is structured like this: <table> ...

Issues with retrieving the output of a function nested within another function through an ajax request

I am attempting to use jQuery to add the results of an ajax call to a paragraph. My goal is to extract the "myResult" variable from the inner getResult function and transfer it to the outer buildParagraph function. Unfortunately, the returned value is und ...

The video attribute in HTML is malfunctioning on the react webpage

Currently working on setting up a basic portfolio layout with a video playing in the background on loop. However, despite making some adjustments and modifications, the video is not showing up as expected. Any insights or suggestions on what might be causi ...

Align dropdown navigation menu/sorting dropdown in the same position as the button

Exploring the world of dropdown menus in CSS has led me to encounter some challenges. I am striving to ensure that the dropdown boxes appear on the same line as the button that triggers them. Below is the CSS code I have been working with: /* global style ...

I would like to retrieve my data using my personal API and have them displayed as checkboxes

https://i.sstatic.net/qPSqe.jpgHere is an excerpt of the progress I have made main.html (it's actually a form) <div class="form-group form-check-inline"> <input class="form-check-input" type="radio" name=& ...

"Showcasing a pair of icons side by side in an HTML layout

I need assistance with formatting two legends on the form. I want both legends to be displayed side by side instead of one on top of the other. Here's how I want it: -----legendOne---LegendTwo----- What CSS code do I use to achieve this layout? Be ...

Is SCSS automatically compiled into CSS by VSCode?

In the tutorial I followed, the instructor mentioned clicking a button at the bottom of the window to create a CSS file with the 'Live Sass Compiler' extension in VSCode. However, despite following the instructions, the compilation does not seem ...

Achieve vertical alignment and responsiveness of elements in primefaces using css techniques

In order to vertically align 2 elements inside an outputpanel, I initially used a margin-top of 3em. However, this method proved to be non-responsive, as shown in the following images: https://i.sstatic.net/yMRXc.png In mobile view: https://i.sstatic.net ...