CSS Troubleshooting: oversized div

I want to adjust the size of my lightbox, but I'm facing some issues. When I set max-width: 100%, the images appear too large for PC screens (img) and too small for cellphones (img). Conversely, with a max-width: 50% setting, the images are just right (img1 and img2). What should be my approach?

CSS:

/* The Modal (background) */
#galeria .modal {
    display: none; /* Initially hidden */
    position: fixed; /* Fixed position */
    z-index: 1; /* Top layer */
    padding-top: 100px; /* Positioning */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Scroll enabled if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.6); /* Black with opacity */
}

/* Modal Content */
#galeria .modal-content {
    margin: auto;
    padding: 20px;
    max-width: 50%;

}

HTML:

<!-- The Modal -->
<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">

  <div class="close-button"><span class="close" id="close-sync">&times;</span></div>
    <div id="sync1" class="owl-carousel">
    <div class="item">
          <img src="assets/img/eventos/16-12-2016/01.JPG">
      </div>
    <div class="item">
          <img src="assets/img/eventos/16-12-2016/02.JPG">
      </div>
    </div>

    <div id="sync2" class="owl-carousel">
      <div class="item">
          <img src="assets/img/eventos/16-12-2016/01.JPG">
      </div>
    </div>

  </div>

</div>

Answer №1

If you're looking to optimize your website for different screen sizes, consider using media queries:

#gallery .modal-content {
    margin: auto;
    padding: 20px;
}
/* adjust for phone screens */
@media screen and (max-width: 600px) {
    #gallery .modal-content {
        max-width: 100%;
    }
}
/* optimize for larger screens */
@media screen and (min-width: 601px) {
    #gallery .modal-content {
        max-width: 50%;
    }
}

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

Concealing an Automatically Updated Section when Devoid of Content -- Ruby on Rails Version 4

I have come across various solutions to this problem, but none of them seem to be effective for my specific project. In my application, the user's previous choices are displayed in multiple divs. Initially, all the divs are empty. As the user progress ...

Customizable Data Tables with Jquery Datatables

Currently, I am in the process of creating a customizable data table using Jquery's Datatable plugin. The goal is to allow users to edit, remove, update, and add columns to the table. To achieve this functionality, I have been experimenting with the f ...

Adjusting the padding of an HTML element according to the width of the element that comes before

I'm currently working on formatting a Shakespearean script using HTML. Since Shakespeare's writing follows a specific meter, it is common practice to indent lines that do not start on the first beat of the meter. Here's how it's usually ...

Steps for automatically collapsing the sidebar on mobile devices when the page loads

I recently purchased the Lexa bootstrap admin dashboard from Envato Elements, but I'm encountering a problem. When viewing it on mobile, the sidebar does not collapse by default. The Metis Menu is being used for the sidebar, and clicking on the toggle ...

Regenerate main JavaScript files in Gulp whenever partials are edited

In my gulp task for javascript files, I included partial js files in the source and filtered them out to avoid building them unnecessarily. gulp.task("js", () => { return gulp .src([ src_js_folder + "*.js", src_js_f ...

Efficiently perform complex nested grouping using the powerful array

Hi, I'm currently facing difficulties while attempting to utilize the array.reduce() function in order to achieve correct grouping for a specific scenario: Here is my original array: { { descriptionFunction: "Change", processDate: "201 ...

Creating a form in NextJS to securely transfer user input data to MongoDB

Being new to JavaScript, I have a basic understanding and some lack of experience, but I am eager to learn more. Recently, I embarked on a project using NextJS, an efficient framework that integrates with ReactJS. My current challenge lies in creating a si ...

Showing content in a way that spaces out below the text

Could someone assist me with a CSS problem I'm having? I understand CSS, but debugging is not my strong suit. When I use display: inline-block for both my Academic Information and Personal Information, I'm getting extra white space below (above " ...

"Struggling to get basic jQuery to function properly after uploading it

After diving into jQuery and experimenting with basic functions, I've been testing my code on various platforms. The strange thing is that the code functions perfectly on all browsers (Safari, Chrome, Firefox) when it's locally hosted on my mac ...

I want to modify a script for toggling a div's visibility to utilize a select dropdown menu instead of radio buttons

CSS @charset "utf-8"; /* CSS Document */ body,td,th { font-family: "Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif; font-size: medium; } body form select { font-family: "Gill Sans", "Gill Sans MT", "Myriad ...

The visibility of overflow-y does not seem to be working properly when overflow-x is

https://i.sstatic.net/hihjC.png .iati-list-table { overflow-x: auto; overflow-y: visible; } When I apply overflow-visible, a scroll bar appears. But when I use overflowy-hidden, the tooltip is cropped. How can I set it so that overflow x is auto a ...

Preventing window.load events from firing in JavaScript

Recently, I was playing around with a chrome extension that I had developed on various websites. The purpose of the extension was to print out the web address of the site once the entire page loaded completely. However, when I looked at the plugin's J ...

unable to implement $http method in angular.js

I am attempting to retrieve data from a web API. When running on a single HTML page, I receive the response with the data successfully. However, if this script is written separately (outside the HTML page), I am unable to fetch the data. This is the first ...

Is there a way for me to automatically go back to the home page when I press the back button on the browser?

My ecommerce website has a shopping cart page where customers can purchase products and make payments. After the payment is completed, they are directed to a thank you page. The flow of the website is as follows: Home page => Products => Shopping ca ...

Is there a way to replicate this exact toggle selection functionality from Angular Material using just HTML and CSS?

I'm attempting to incorporate this functionality into my Angular project ( link ), but I'm facing challenges with styling it using CSS. Could this be due to limitations in overriding the default settings? I came across this helpful resource: sour ...

Using Spry Validate for form validation in conjunction with Ajax submission

I'm currently facing an issue where I want my form to validate before the ajax call is made, but I can't seem to figure out the correct coding for this process. When I separate them, I am able to either post using ajax without validation or with ...

What is the best way to center and adjust the size of an image in a jumbotron?

I need some assistance with centering and resizing an image above my navigation bar. I want the image to be positioned right above the navigation bar, similar to how it appears on other websites. Can anyone help me achieve this? .jumbotron { text-alig ...

Tips for retrieving a td element from an HTML document

I have a variable containing HTML data and I need to extract a specific td element from it. When I use the alert(returnData) function, it displays the following output: <tr class='addedrow'> <td id="abc">DOM-001 <inpu ...

The interactive form fields are not functioning as intended due to a dynamic association issue

Issue with Adding Two Dynamic Form Fields Together I need to add two fields at once by clicking a single button, and each field should have a two-dimensional name structure like [0][0] and [0][1] for saving dual values Although I used jQuery to dyn ...

Using the power of jQuery to load Ajax content, unfortunately, the content remains

Hey there, I'm currently working with an HTML file that utilizes AJAX to load content from other HTML files on the same server. However, for some reason, it's not functioning properly. I'm new to AJAX and I'm not sure what could be caus ...