Having trouble finding the right position, body extending beyond the viewport?

I've encountered a puzzling issue... I attempted to position an element at the far right of the page using CSS 'right: 0px'. However, it appears that my element is actually being placed slightly further right than intended, causing part of it to be cut off.

In order to troubleshoot the problem, I have simplified the scenario to the following HTML code.

It appears that an element with a width of 100% (including the body!) is wider than the viewport, yet still triggering scrollbars. It's quite perplexing… What am I missing here?

<!DOCTYPE html>
<html>
<head>
    <style>

        body{
            overflow: auto;
        }

        #div1{
            position:       absolute;
            top:            50px;
            left:           0px;
            width:          100px;
            height:         145px;
            background-color:   red;
        }

        #div2{
            position:       absolute;
            top:            250px;
            left:           0px;
            width:          100%;
            height:         145px;
            background-color:   red;
        }

        .block{
            position:       absolute;
            width:          30px;
            height:         20px;
            background-color:   yellow;
        }

        .sub0{top:0px; right:0px;}
        .sub1{top:25px; right:1px;}
        .sub2{top:50px; right:2px;}
        .sub3{top:75px; right:3px;}
        .sub4{top:100px; right:4px;}
        .sub5{top:125px; right:5px;}

    </style>

</head>


<body>

    <div id="div1"> 

        <div class="block sub0">0PX</div>
        <div class="block sub1">1PX</div>
        <div class="block sub2">2PX</div>
        <div class="block sub3">3PX</div>
        <div class="block sub4">4PX</div>
        <div class="block sub5">5PX</div>

    </div>

    <div id="div2"> 

        <div class="block sub0">0PX</div>
        <div class="block sub1">1PX</div>
        <div class="block sub2">2PX</div>
        <div class="block sub3">3PX</div>
        <div class="block sub4">4PX</div>
        <div class="block sub5">5PX</div>

    </div>

</body>

</html>

Answer â„–1

Sorry for the inconvenience, but I figured out the problem. It was quite silly and made me feel like banging my head against the wall...

Further investigation revealed that the issue only occurred when the browser window was maximized on the left monitor of my two-monitor setup...

An auto-adjustment of the monitor resolved the issue, no longer losing those right 2 pixels...

DUH! Lesson learned!

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 identifying modifications in an input text field and activating the save button

Currently, I am developing a function that can detect any changes made in the text field and then activate the save button accordingly. This code is being executed in Visual Studio 2017, using HTML and JavaScript. (function () { var customer_addres ...

PHP contact form not properly sending complete submission data

I'm facing an issue with my HTML contact form that utilizes JavaScript for a change function. Essentially, I have a dropdown menu for different subjects, and based on the selected option, specific fields should appear. However, when a user fills out t ...

Tips for overlaying an image on a div regardless of its height

(!) Although this question may seem repetitive, I have not been able to find a suitable solution in any of the previous 10 topics. I apologize for the inconvenience and am actively seeking a resolution to this unique situation; Allow me to outline the iss ...

Ensure that when you click on the next dropdown menu opener button, the previous dropdown menu closes and only the new menu remains open

Take a look at this page first to get an understanding: On this page, I have implemented multiple dropdown menus that should open when clicked on their respective opener buttons (3 bar icon) and close either when clicked again or anywhere else on the page ...

"Even rows are the only ones being highlighted on the table

I created a table that dynamically highlights all odd rows. To achieve this, I implemented a method to identify the row number and then apply the alt class to those specific rows. In order to highlight the rows on hover, I added a simple :hover selector ...

Issues with the CSS styling

Struggling with styling my menu and can't seem to get it right. Feeling a bit lost as I'm new to this. .customHorizontalList { list-style: none; display: flex; flex-direction: row; } .customHorizontalList>li { margin-ri ...

Enhancing the Search Bar in Bootstrap 4 Dashboard Template: A Step-by-Step Guide

Recently got my hands on the Bootstrap 4 Dashboard template and decided to enhance it by adding a form to the top search bar. However, I encountered an issue where the search bar shrinks and loses its original design. If you want to check out the Bootstra ...

The use of a custom padding on a text input with the Bootstrap 3 form-control class can cause the text to be hidden

It seems like the code is working fine in Opera and Chrome, but in Firefox and IE11, the text is getting hidden, which is not very enjoyable. I don't have a Mac, so I can't test it on Safari. You can see the issue in action on this Plunker. I&a ...

Footer positioned correctly with relative DIV

I find myself in a state of complete confusion. Coding is not exactly my forte, so I suspect I have made a significant error somewhere that is causing the following issue: My goal is to create a sticky footer. The footer does indeed stick to the bottom of ...

Challenge encountered with AJAX request

Whenever I trigger an AJAX request to a JSP using a dropdown menu, it works perfectly fine. However, when I try to trigger the same request using a submit button, the content vanishes and the page refreshes. function najax() { $.ajax({ url:"te ...

Exploring the differences between SASS and Bootstrap: the battle of mixins versus @extend

Currently utilizing the SASS version of Bootstrap found here. Curious as to whether there are distinctions between using the pre-set mixins versus utilizing SASS's @extend. For example, considering the following: <div class="wrapper"> Some ...

Verify the visibility of the toggle, and eliminate the class if it is hidden

I have implemented two toggles in the code snippet below. I am trying to find a solution to determine if either search-open or nav-open are hidden, and if they are, then remove the no-scroll class from the body element. $(document).ready(function() { ...

In configuring the print settings, I specified margins to ensure proper formatting. However, I noticed that the margin adjustment only applies to the first page. I need

I have a method that retrieves margin top value from the backend. It works perfectly on the first page of print, but on the second page, the margin top space is missing. initializePrintingSettings() { this.printService.fetchPrintSettings().subscribe(respon ...

I'm struggling to activate the eventListener on several elements with the same className or ID. Unfortunately, only the initial child is being triggered in my current code implementation

Hello fellow developers, I'm facing an issue while working on a project. I have about ten menu items with the same ID, and I want to be able to edit each one when it is clicked. Here's what I tried using JavaScript: const menuElement = d ...

Styling Material UI height in select elements (React)

Currently, I am developing a react application that utilizes Material Dashboard. I am encountering an issue with the height of a Select (drop-down list) component. See image here On the right side of my app, there is a standard input field and I would li ...

Updating the value of an Angular select on change is not being reflected

If the select element is changed, the value should be set to something different from what was selected. There's a feature in place that only allows 4 item types to be selected at a time; if more than 4 are chosen, the value reverts back to its origin ...

A triangular-shaped div positioned at the bottom with a captivating background image

Is there a way to create a div with a unique twist - a triangle shape at the bottom? I've been attempting to add a background image within the triangle using a pseudo element (:after), but so far, it hasn't been successful. #homebg:after{ co ...

Divergent outcomes observed in various browsers when fetching XMLHttpRequest responseText

Utilizing XMLHttpRequest responseText to retrieve a server txt file and populate the contents of that file into an editable text box has been my recent task. The txt file consists of concise lines of letters separated by new lines. Users have the option to ...

Encountering the issue "Error: Uncaught PDOException - SQLSTATE[42000] - Syntax error or access violation: 1064"

I encountered an error that says: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064. It seems to be a syntax error in my SQL statement. Can you help me figure out what's wrong with it? require_once "dbconnect.inc.php"; $e ...

Steps to position images and text side by side in a grid layout

Trying to create a grid layout with profile images and text aligned next to each other, but struggling with CSS. If anyone could provide some guidance, that would be greatly appreciated! Here is the HTML code snippet: <div class="col-sm-3" ...