What is the best way to horizontally scroll and maintain the center alignment of a fixed-width div, especially when it exceeds the width of the browser window?

My current setup is almost perfect, but I am struggling to keep the green rectangle centered on the browser between 835px and 320px width. Any solutions using CSS or JavaScript are welcome.

This is my first time posting a question on stackoverflow, so I hope I have provided enough information. Thank you in advance for your help.

<!DOCTYPE html>
<html>
<head>

<style>

body {
    margin: 0;
    padding: 0;
}

.bottles-container-mobile .container-fluid {
    overflow: auto;
    background: #ccc;
}

.product_map_image_mobile {
    width: 835px;
    height: 359px;
    overflow: auto;
    overflow-y: hidden;
    margin: 0 auto;
    white-space: nowrap;
    position: relative;
}

.product_map_image_mobile .product_map_link_mobile {
    display: inline-block;
    position: absolute;
    text-indent: -999em;
    overflow: hidden;
}

/* Styles for different elements within the product map image */
.product_map_image_mobile #product_map_link_mobile_0 {
    width: 77px;
    height: 193px;
    top: 117px;
    left: 20px;
    background:blue;
}
/* Repeat styles for other elements here */

</style>

</head>
<body>

<div class="wrapper">
    <div class="bottles-container-mobile">
        <div class="container-fluid">
            <div class="row-fluid">
                <div class="product-solutions-green-bar-mobile">
                    <div class="product_map_image_mobile">
                        <a class="product_map_link_mobile" id="product_map_link_mobile_0" title="" href="#"></a>
                        <a class="product_map_link_mobile" id="product_map_link_mobile_1" title="" href="#"></a>
                        <a class="product_map_link_mobile" id="product_map_link_mobile_2" title="" href="#"></a>
                        <a class="product_map_link_mobile" id="product_map_link_mobile_3" title="" href="#"></a>
                        <a class="product_map_link_mobile" id="product_map_link_mobile_4" title="" href="#"></a>
                        <a class="product_map_link_mobile" id="product_map_link_mobile_5" title="" href="#"></a>
                        <a class="product_map_link_mobile" id="product_map_link_mobile_6" title="" href="#"></a>
                        <a class="product_map_link_mobile" id="product_map_link_mobile_7" title="" href="#"></a>
                        <a class="product_map_link_mobile" id="product_map_link_mobile_8" title="" href="#"></a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


</body>
</html>

Answer №1

Here is a possible solution:

@media screen and(max-width:835px) and (min-width:320px) {
    .product_map_image_mobile {
        width: adjusted_widthpx;
    }
}

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

problems with basic text styling in containers

I've been experimenting with text in boxes and I've noticed that when the screen size changes, extra padding is added to the top of the box even though it's not in the code. Is there a way to prevent this from happening when the screen resiz ...

Leveraging Vue.js plugin within a single file component

I am looking to utilize the vue-chartkick plugin in my Vue application, but I want to register it within my single-file components instead of globally. Is there a way to achieve this same functionality without using Vue.use(VueChartkick, { Chartkick })? ...

The positioning of the jumbotron image is off-center

I'm facing an issue with the header code. The image is not centered properly when I switch between different sizes. Is there a way to ensure that the image is centered in all size views? <div class="jumbotron"> <img src="images/hea ...

Is the Flowplayer JS API malfunctioning due to Flowplayer not being properly 'loaded'?

On a webpage, I have implemented multiple videos to autoplay using Flowplayer and jQuery with the following code: $('.video').each(function (k, obj) { $(obj).flowplayer(...) }) These videos are streaming and start playing automatically. At a ...

Using three.js to set the HTML background color as clearColor

How can I set the HTML background as clearColor using three.js? Here is the code snippet for three.js: // Setting up the environment var vWebGL = new WEBGL(); var scene = new THREE.Scene(); var camera = new THREE.PerspectiveCamera(75, window.innerWidth / ...

Is there a way to determine the distance in miles and feet between various sets of latitude and longitude coordinates?

I am working with an array of latitude and longitude coordinates and I am looking to use JavaScript or Typescript to calculate the distance in miles and feet between these points. const latsLngs = [ { lat: 40.78340415946297, lng: -73.971427388 ...

Can Javascript (PWA) be used to detect fake GPS or mock GPS in applications?

Looking for a solution to prevent users from using Fake Location tools in my PWA application that gathers absence location data. Is there a method or package in JavaScript to detect the presence of Fake GPS installed on the device? ...

How to center align a fixed div position

I am looking for a way to center align a fixed position div on my page. In the past, I have been able to achieve this with absolutely positioned divs using a specific technique. left: 50%; width: 400px; margin-left: -200px; However, this method does no ...

The power of MobX lies in its ability to provide a deep

I'm currently delving into the concept of deep observability in MobX. I'm looking for insights on why the autorun function is not being triggered every time I call setCommentCountForPost in the code snippet below. Can someone point me in the rig ...

Hide the background when the modal appears

I have successfully implemented a jQuery CustomBox modal on my website. However, I am facing an issue with hiding the content div behind the modal once it pops up. My goal is to make the content div reappear after the modal has been closed. You can view a ...

Display the value of the dynamically added selected element only

Is there a way to display the selected element value on click without showing all element values? In the code below, when I add usernames and click on any label, it should only show the corresponding delete icon. However, currently, it shows delete icons f ...

PHP: Syntax error: unexpected empty string (T_ENCAPSED_AND_WHITESPACE)

When trying to retrieve values from a SQL database and set them as unique options for Radio buttons, I am encountering an error. I believe the issue lies in how I am passing PHP code within the value parameter. Can someone please provide guidance on how to ...

Exploring jQuery Animation Effects: Enhancing Your Web Experience with Zoom In and Zoom Out

Is there a way to animate a logo using jQuery automatically upon page load? I want the image to zoom out, then zoom in and change to a different image. Can someone please assist me with this task? Below is the code snippet that I have: $(document).ready ...

SB Admin 2 menu with multiple levels does not collapse as expected

I'm in the process of integrating the menu from the sb admin 2 template into my Ruby on Rails application: As I gradually added components to test functionality, I successfully implemented the top and side nav bars. However, I encountered an issue wi ...

AngularJS seems to be ignoring CSS styles when displaying list items in the ng-repeat loop

After coming across a tutorial on creating round circles connected by a line in CSS, I decided to implement it myself. Interestingly, everything worked perfectly fine when I tested it with static HTML. However, when I tried to make it dynamic using Angular ...

Content changing programmatically does not reset the scrollHeight

As I embark on the journey to expand my coding skills, I have decided to challenge myself by tackling some tasks without relying on jQuery. One particular challenge that I am currently facing involves a fixed contenteditable div. The goal is to adjust the ...

What is the process for assigning a value to the body in a div element?

Within a div, there is a body element structured like this: <div id = "TextBox1"> <iframe id = "TextBox1_1"> #document <html> <head></head> <body></body> </html> </iframe> </div> I have attempte ...

Generating variables dynamically within a React Native component

In my React Native component, I need to create a variable that will be used multiple times. Each instance of this component should have a different variable name for reference. <View ref={view => { shapeView = view; }} onLayout={({ nativeE ...

Encountering an Unresolved Runtime Issue: TypeError arises when attempting to access properties of undefined (specifically 'call') while utilizing the Image component in next.js

I'm currently experimenting with the Image component offered by next.js. This Is My Basic Header Component import Image from 'next/image' import React from 'react' import myImage from '../assets/IMG-20221115-WA0001.jpg' ...

Aligning or positioning two divs to be equal in size alongside other divs

I am facing an issue trying to make two divs (.profile-spotify, .profile-games) the same size as .profile-card and .profile-details, or centering them. I've attempted using justify-center, margin auto, and other methods but none have been successful. ...