Using Bootstrap 3's "img-responsive" class can cause images to become distorted when

When an image is rotated 90 degrees inside a modal, the img-responsive feature stops working and the image height exceeds the modal height.

function rotateImage(){
    var angle = ($('#testImg').data('angle') + 90) || 90;
    $('#testImg').css({'transform': 'rotate(' + angle + 'deg)'});
    $('#testImg').data('angle', angle);
}
$(document).ready(function() {
    $('.modal').modal('show');
})
.modal {
  overflow-y: scroll;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Title</h4>
      </div>
      <div class="modal-body">
        <img id="testImg" class="img-responsive" src="http://wallpapercave.com/wp/LYiEQH6.jpg">
        <button class="btn btn-primary" onclick="rotateImage()"></button>
      </div>
      <div class="modal-footer">
        <button type= "button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

Answer №1

Upon examining this example: https://jsbin.com/veranak/edit?html,css,js,output, it becomes apparent that the issue does not lie with the modal.

The responsive image container's height is determined by the width and height of the image itself. The CSS transform property rotates the image without altering the size of its container or the image itself; it simply rotates it.

1) Consider adding a scrollbar to the .modal-body element instead of the .modal:

.modal-body {
    overflow-y: scroll;
}

2) For a more refined solution, you may find guidance in this article:

JSBin code below

HTML:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="image">
        <img id="testImg" class="img-responsive" src="http://wallpapercave.com/wp/LYiEQH6.jpg">
        <button class="btn btn-primary" onclick="rotate()"></button>
</div>

CSS:

.image {
  border: 1px solid;
  margin-top: 5vh;
  padding: 1em;
}

Javascript:

function rotate(){
    var angle = ($('#testImg').data('angle') + 90) || 90;
    $('#testImg').css({'transform': 'rotate(' + angle + 'deg)'});
    $('#testImg').data('angle', angle);
}

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

How can I save a chosen value from a dropdown menu to an SQL table using Bootstrap Editable

I've been working on a project that involves displaying data from an SQL table using bootstrap editable for live editing. So far, everything is functioning well - changes made are successfully transferred to the SQL table. Here's what's alr ...

Error with Gmail displaying incorrect font

I've been struggling to change the font of my emails to Open Sans, especially with Gmail not rendering the correct font. However, I found a workaround for Outlook. Here is what I have: body { @font-face { font-family: 'O ...

What is the best way to retrieve a table from an HTML page and convert it into a data frame using XML and Rcurl in R programming?

Can someone help me convert a table on the Forbes website into a data.frame? Click here to access the table ...

Utilize JSON data fetched from a URL to dynamically populate an HTML content

There is a JSON file located at a URL that looks like this: [{"tier":"SILVER","leagueName":"Tryndamere's Wizards","queueType":"RANKED_SOLO_5x5","playerOrTeamId":"91248124", "playerOrTeamName":"NunoC99","leaguePoints":18,"wins":411,"losses":430,"rank" ...

Present XML data on an HTML page to generate interactive form features

I have an application that features a checkbox tree. I would like to automatically pre-select those checkboxes if the user had previously checked them. To achieve this, I receive XML data from my backend Perl script which contains information on which che ...

Combine Laravel with Vue.js to dynamically load additional data by simply clicking on a button

I'm facing an issue. When I click the button, it fetches the entire database instead of loading a part of it. How can I make it load only a portion of the database? For instance: I want to display 10 posts after each click. Thank you for your assista ...

Bootstrap 4 Date Selector

Is there a different option I can use instead of 'datepicker' because it doesn't seem to be working correctly and I've heard it's not compatible with bootstrap 3+. When I paste the example datepicker code into a blank HTML page, i ...

`Eye tracking scenario requires a specific view matrix to function properly`

In the midst of a small project, I am currently exploring the use of a webcam to track a user's 'eye position' in order to manipulate a threeJS scene or WebGL environment. The goal is to create an illusion that the screen is a window into a ...

The p-dialog lacks the proper styling and does not show or hide correctly

I am working on adding a feature where dragging and dropping an event in a calendar triggers a dialog box that requires the user to confirm if they want to postpone the event. However, I ran into an issue where the styling of my p-dialog is not defaulting ...

Set the userID variable as the assigned value and the username variable as the ng-model attribute for a select

Seeking assistance with a coding dilemma. Currently working on an ASP.Net MVC and AngularJS application, where I am utilizing the select tag to display a list of users. Both the select tag and a div are connected via the same ng-model for real-time binding ...

Error: The Next.js webpack module is missing in the npm local package

I'm currently developing a Next Js application that utilizes its mongoose models from a local npm package, allowing for shared functionality across different backend components. However, I am encountering the following errors: Module not found: Can&ap ...

Is it possible to include a JavaScript script in a Laravel Blade file?

I have an Auth module from nwidart/laravel-Module. I am trying to include a script file in the Modules\Auth\Resources\views\layouts\app.blade.php file, like this: <body> ...... ... <!-- Scripts --> <script s ...

Nested functions with async-await syntax

I'm attempting to showcase a nested countdown utilizing two nested loops. You can access the complete, functional code on this js.fiddle link. Two key segments are highlighted below: function sleep(ms) { return new Promise(resolve => setTime ...

I successfully merged two arrays (decks of cards) without using recursion, but I'm curious to understand where I went wrong with the recursive approach

Currently, I am working on a function that shuffles two arrays together using recursion. The goal is to combine the top and bottom halves of a deck of cards into a single array with elements interleaved. For example: The first element should come from the ...

The buttons are off-center on the page when the screen width is below 1199px, they should be centered instead of aligned to the

Using Bootstrap 5, I've successfully created a layout with aligned rows of buttons at 1200px and above. However, an issue arises at the XL breakpoint (1199px) where the buttons align to the left of the container instead of being centered. You can vie ...

Nodemon isn't functioning properly: nodemon isn't loading as expected

db.js const mongoose = require('mongoose'); const mongoURI = "mongodb://localhost:27017/?readPreference=primary&appname=MongoDB%20Compass&ssl=false"; const connectToMongoDb = ()=>{ mongoose.connect(mongoURI, ()=>{ ...

Why is the text getting covered by the drop down menu?

I am currently working with bootstrap classes and I am facing an issue where the drop down menu is overlapping with the text. You can see the problem in the screenshot here: enter image description here <div class="collapse navbar-collapse" ...

Revise the cascading style sheets for HTML content loaded via AJAX

I have a situation where I am dynamically loading HTML content using AJAX with JQuery. After the content is loaded, I am triggering a click event on specific elements within the newly added HTML. However, I am encountering an issue when trying to set the ...

Utilizing the power of Vue 2 and NuxtJS to effortlessly customize the appearance of child components

I am currently working on a Nuxt.js project (still using Vue 2) that consists of two components. I am trying to override the child style with the parent's style, but the ::v-deep pseudo selector doesn't seem to be effective. Regardless of my eff ...

Enhancing the validation of multiple selects using jQuery

Here is what I have accomplished so far: JSFIDDLE My current goal is to: add the class "invalid" to the <select> if it was not selected in its respective row remove the "invalid" class if all 3 selects in the row are selected automatically submit ...