The placement of my image shifts when I switch to the mobile view

Having a small issue with my image alignment. When I switch from portrait to landscape view, the image is no longer centered. The margin remains the same as in portrait view and I'm unsure how to adjust it.

I've attempted changing the margins of the images, but it still retains the initial portrait view margin settings.

Here's the Js/Jq code snippet:

function puceTransition(front) {
    var wrapImg = $('.wrapImage');
    var margeLeft = 0;

if(front) {
    if (stateImg == "back") {
        stateImg = "front";

        margeLeft = $('#myImageBack').css("marginLeft").replace("px", "");

        $('#frontImg').addClass('select');
        $('#backImg').removeClass('select');

        $('#myImageBack').animate({opacity: "0.5", marginLeft: ((imgFront + widthImg1 + myButtonRight)) + "px"}, "normal");
        $('#myImageFront').animate({opacity: "1.0", marginLeft: parseInt(margeLeft) + "px"}, "normal");

        $('.imgTitleBack').hide();
        $('.imgTitleFront').show();

        $('#imgButtonLeft').animate({opacity: "0.5"});
        $('#imgButtonRight').animate({opacity: "1.0"});
    }
} else {
    if (stateImg == "front") {
        stateImg = "back";

        margeLeft = $('#myImageFront').css("marginLeft").replace("px", "");

        $('#backImg').addClass('select');
        $('#frontImg').removeClass('select');

        $('#myImageFront').animate({opacity: "0.5", marginLeft: (((-imgFront) + (-widthImg1) + myButtonLeft)) + "px"}, "normal");
        $('#myImageBack').animate({opacity: "1.0", marginLeft: parseInt(margeLeft) + "px"}, "normal");

        $('.imgTitleBack').show();
        $('.imgTitleFront').hide();

        $('#imgButtonLeft').animate({opacity: "1.0"});
        $('#imgButtonRight').animate({opacity: "0.5"});
    }
}
}

And here are the corresponding CSS styles:

.myImage { display: block; position: relative; width: 450px; margin: 0 auto; }
.myImage.second { margin: -240px 0 0 670px; }
.myImageAirport { display: block; position: relative; width: 450px; margin: 0 auto; }
.myImageAirport.second { margin : -220px 0 0 670px; }

Answer №1

To style your image class, simply include this CSS:

.imageStyle {
display: block;
margin-right: auto;
margin-left: auto;
}

Try it out and see the results!

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

Unusual styling: Unexpected CSS :after impact on card layouts in Bootstrap 4

I'm currently utilizing a Bootstrap 4 masonry card layout for a particular project, and within this project, there is a <select> element that has been styled with custom CSS properties. One of the customized styles includes a caret created using ...

When uploaded to Amazon CloudFront, web application routes fail to function properly

I am facing an issue with my Next.js single page app that utilizes static paths. When running it locally or exposing it directly from an AWS S3 distribution, everything works fine. However, once served via AWS CloudFront, accessing paths other than the roo ...

JS: I'm struggling to understand the scope

I've been working on adapting CouchDB's JS API to function asynchronously, but I'm encountering an unresolved error: You can find my version of the JS API here on Pastebin. Whenever I execute (new CouchDB("dbname")).allDocs(function(result) ...

Concealing spinner controls on HTML Ionic number input

Seeking a foolproof method to conceal spinner buttons on an HTML template for Ionic's number input field. Showcased below is the HTML code that exhibits an input with spinner buttons: <ion-input type='number'></ion-input> The ...

The border in my HTML table is not displaying when I run my flask application

My flask application was running smoothly in a virtual environment until I encountered an issue with the html borders not showing up. Even after seeking help from a friend who knows some html, the problem still persists. app.py: from flask import Flask, r ...

Retrieve and manipulate the HTML content of a webpage that has been loaded into a

Hey, let's say I have a main.js file with the following code: $("#mirador").load("mirador.html"); This code loads the HTML content from mirador.html into index.html <div id="mirador"></div> I'm wondering if there is a way to chan ...

How can we refresh the model in Angular.js from a section of the application that has not been 'angularized' yet?

UPDATE: Found a similar question at Call Angular JS from legacy code Working on adding a new feature to an existing application using Angular. Unable to do a complete rewrite, so the challenge is integrating Angular models with the rest of the app that di ...

Display a portion of the existing URL as a clickable link on the webpage using JavaScript or PHP

If I have a website with the URL and I would like to showcase the image at https://example.com/image.jpg on my site (), what can I do? I attempted the following approach, but it only displays the URL of the image. <p id="image"></p> <scri ...

Troubleshooting Socket.IO Communication: Client's emits not reaching server

I have implemented a real-time notification service in a web app using Express and Socket.IO. The client can successfully connect to the server and receive emits from it. However, I am facing an issue where the server is not receiving emits from the client ...

Struggling with implementing the group by feature in AngularJS?

Currently, I am trying to group a select-window by 2 different object arrays - subcategories and rootcategories. Each subcategory has a relation id that links to the rootcategory's id. My goal is to have the dropdown window group the subcategories bas ...

Deciding Between Two Columns or One Column for Your JQuery Accordion

I am currently working on customizing an Accordion that is too large in height for my liking. My goal is to convert the single column layout into a two-column display, side by side. Having multiple items in one column results in excessive height, hence t ...

Is it possible to transfer state to the getServerSideProps function in any way?

As a newcomer to next.js, I have a question about passing page state to getServerSideProps - is it achievable? const Discover = (props) => { const [page, setPage] = useState(1); const [discoverResults, setDiscoverResults] = useState(props.data. ...

css how to style a table row with a specific identifier

Although this question has been asked millions of times on the internet, my English skills are not great and I struggle to find the right words to search. I have a table with a specific ID set up like this: <table class="tableClass"> <tr id="one ...

Unveil the Expressjs middleware within the API Client

I am currently developing a Nodejs API Client with the following simple form: //client.js function Client (appId, token) { if (!(this instanceof Client)) { return new Client(appId, token); } this._appId = appId; this._token = tok ...

Unlocking secrets: Displaying PIN/ Password using Bootstrap pincode-input.js

I am using Bootstrap's pincode-input.js to mask the PIN on my web app. However, I would like the PIN to be initially hidden, and only revealed when the user clicks the show button. Can anyone help me with this? Thank you in advance. <input type="t ...

Tokenizer method utilizing strings

Imagine a scenario where strings adhere to this specific format: id-string1-string2-string3.extension In this case, id, string1, string2, and string3 can all vary in length, with extension being a standard image extension type. To illustrate, here are a ...

Why is Selectpicker failing to display JSON data with vue js?

After running $('.selectpicker').selectpicker('refresh'); in the console, I noticed that it is loading. Where exactly should I insert this code? This is my HTML code: <form action="" class="form-inline" onsubmit="return false;" me ...

Emscripten WebAssembly: Issue with Exporting Class "Import #13 module="GOT.func" error: the module does not exist as an object or function"

Exploring the potential of WebAssembly in a project as an importable function module, I decided to dive into using C++ with Emscripten. Implementing functions was smooth sailing, but running into obstacles when it comes to classes. My goal is to expose and ...

What is causing Angular to show undefined when using an object?

I'm relatively new to Angular development. I am currently working on a controller that involves validating user input for registration. svs.controller('registrationCtrl', function($scope, validatorService) { $scope.$watch("registrationFor ...

Adjust the spacing of a div based on the fluctuating height of another dynamically changing div

Is it possible to dynamically adjust the margin of a div using jQuery or JS? Currently, I have set a margin on a div by calculating the height of a container that includes images. var articleImageHeight = $('.slides_control').height(); $(' ...