Problem arises with background image scaling and adaptability

Utilizing Magnific Popup for presenting two sections of content side by side has been a bit challenging. The left section features a div with a background image that varies in size, causing issues with responsive styling to fit the containers properly.

Currently, I have resorted to manually setting widths and heights for each image, but I would prefer a more flexible approach. I have chosen to use background images instead of img elements to allow for different images on mobile devices.

I have experimented with different combinations of background-size, position, and height values without success. I believe understanding the root cause of the issue will lead me to a solution. My hunch is that the problem lies within one of the image div's containers.

HTML:

<div class="left-half">
<div class="popup-screenshot" id="mts-screenshot"></div>
</div>
<div class="right-half">
<h3>Description</h3>
<p>Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.</p>
<p>
<h3>Details</h3>
<ul>
<li><span>Date:</span> December 2011 - Present</li>
<li><span>Category:</span> Design/development</li>
<li><span>Technologies:</span> XHTML/CSS3, JavaScript/jQuery</li>
</ul>
</p>
<p><a href="http://www.mtscollective.com" target="_blank" class="btn btn-primary btn-xl">Launch Website</a></p>
</div>

CSS:

.left-half, .white-popup .right-half {
  margin: 20px;
}
.left-half {
  width: 50%;
  float: left;
}
.right-half {
  width: 40%;
}
.popup-screenshot {
  width: 600px;
  height: 450px;
  background-size: 100% 100%;
}
#mts-screenshot {
  background-image: url("http://i.imgur.com/upKnQUT.png");
}
div#mtsm-popup {
  max-width: 800px;
}
div#mtsm-popup .left-half {
  width: 30%;
}
div#mtsm-popup .right-half {
  width: 55%;
}
div#mtsm-screenshot.popup-screenshot {
  width: 266px;
  height: 542px;
  background-size: 100% 100%;
}
#mtsm-screenshot {
  background-image: url("http://i.imgur.com/NghCrTD.jpg");
}
#api-screenshot {
  background-image: url("http://i.imgur.com/Wysc9he.png");
}
.right-half {
  float: right;
  text-align: left;
}

Demo: http://jsfiddle.net/3gLyhad3/1/

Any assistance on this matter would be greatly appreciated!

Answer №1

To begin with, it is essential to note that pixels originated in the 90s and if your goal is responsiveness, consider using units such as vw (viewport width), vh (viewport height) and %. These units are specifically designed for responsive websites and will automatically adjust when you resize your browser window. It's important to remember that 100vw equals 100%.
Additionally, remember to include 'center top' after your url-css-function to prevent the background image from displaying incorrectly.
Furthermore, it typically doesn't make sense to set both the width and height of an element; instead, choose one dimension to define a specific value and set the other one to 'auto'.

Here's a helpful tip: You can use '@media' rules to apply styles only under certain conditions. For instance:
@media screen and (max-width: 768px) { .left-half { width: 80%; } }

By implementing this code snippet, the '.left-half' element will have an 80% width when the screen size is less than 768px on a screen device.

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

Change the right border style for the second and third ToggleButtons in the ToggleButtonGroup

I've been working on this for a few hours now and I can't seem to get it right. Currently, I'm using Mui v5 and trying to style the ToggleButtons to look like regular MUI buttons. So far, I was able to achieve this transformation: https:/ ...

The revolutionary Bootstrap 8 grid layout system

I am in need of a system that consists of 8 columns, and I require a Bootstrap class that will allow an HTML element to span across 2 or more of the columns within the grid. The purpose of this is to create a PMS (Property Management System), where certai ...

Using jQuery to retrieve the tag name of the selected element

What is a simple method for retrieving a tag name? For instance, if I input $('a') into a function, how can I extract the tag name 'a'? ...

Three fixed position divs arranged horizontally side by side

I am attempting to organize 3 divs in a row using Flex. ISSUE 1: The div that is centered is set with position: fixed. However, the two other divs on each side do not stay aligned with the centered fixed div when scrolling. If I change the centered div to ...

Using Bootstrap's dual listbox, you can easily select single options with the ability to add or delete them. Upon selection, the

Could someone please assist me in resolving this issue? I am looking for a dual listbox with single select option, unlike Bootstrap which only offers dual listboxes with single/multiple select. To Clarify: Here is an example: In my dual listbox, the le ...

The alignment of text in the flex column is incorrect on the right side

The flex column I created is having an issue with the arrow on the right side. It's not displaying properly and is hidden. The arrow should be similar to the one on the left and point to the left direction. I have used left: 0; for the left side and ...

Setting an image or color at specific map coordinates in HTML - a step-by-step guide!

Is it possible to implement colors within the coordinates of a map instead of using transparent clickable spaces? Specifically, when clicking on a circle, the color should transition, for example, from red to blue. Although I attempted using background-co ...

Extracting text within quotation marks from HTML using Java and Selenium WebDriver

I encountered a piece of code that resembles the following: https://i.stack.imgur.com/gaX1J.png Although I am able to retrieve the link using the command System.out.print(link.getText()); it only returns the value "Saab". However, I also require the da ...

Changing the text color and background color of a span element when a ng-click event is triggered

There are two buttons, Today and Tomorrow, each with an ng-click function. By default, the button background color is white and text color is red. When the Today button is clicked, the background color changes to blue and the text color changes to white. ...

What is the best way to assign a Python variable to an <a-assets> element?

There exists a Python function that provides the chosen background <a-sky ID="sky" color="{{object.background}}"></a-sky> The backgrounds can be in the format of '#c6aa99', '#e1a600', '#290942', 'star' ...

Tips for choosing the default tab on Bootstrap

I have a question about an issue I am facing with my Angular Bootstrap UI implementation. Here is the code snippet: <div class="container" ng-controller='sCtrl'> <tabset id='tabs'> <tab heading="Title1"> ...

Tips for aligning text vertically in flexbox arrangements

As I work on building my portfolio, I have implemented links as buttons using flexbox to make responsiveness easier. The height of these flexboxes is set dynamically using JavaScript with percentages. Despite trying various suggestions, none of them provi ...

Expand the div width to the specified measurement horizontally

Is there a way to horizontally collapse a div (container) to a specific width that I can adjust, effectively hiding its content? The collapse effect should move towards the left. <div id="container"> <button type="button" id="myButton"> ...

Combining data from an API using Vue for seamless integration

I need to extract data from an API, such as imdbID, and then append ".html" to it in order to create a variable that can be placed inside the href attribute of a button. However, I am facing difficulties in achieving this. Thank you in advance for your hel ...

Connecting a string array to the navigation bar

Need Assistance with AngularJS: In my controller, I have a string array that looks like this: var app = angular.module('myApp', []); app.controller('mycontroller', function($scope) { $scope.menuitems =['Home','About&apos ...

Update the appearance of a cell if the value within it is equal to zero

I have discovered a way to achieve this using inputs. input[value="0"] { background-color:#F7ECEC; color:#f00;} Now, I am looking for assistance in applying the same concept to table cells. Can anyone provide guidance? Thank you. ...

Incorporating both an X button and hamburger menu is essential in my Bootstrap design, especially since I am working with React.js

Currently, I am working with the most recent version of Bootstrap and aiming to switch between the recognizable X icon and a hamburger menu. It seems like these two icons are overlapping each other, and I'm unsure if I can modify the default 3 lines o ...

Please explain the display property used in Bootstrap input groups

I have been working on implementing a button that toggles the visibility of a datepicker when clicked. <a class="btn btn-primary btn-lg mr-5" href="../Stores/stalls.html">Check Current Operating Stalls </a> <div style="vertical-align: t ...

Even after dynamically removing the class from the element, the Click event can still be detected

My buttons have a design like this: <a class="h-modal-btn branch-modal-btn"> Buy Now </a> The issue arises when I need to remove certain classes and add attributes to these buttons based on the query string in the URL. Skipping ahead ...

Select DOM Elements Using JavaScript CSS Queries

As I delved into JavaScript in an attempt to craft my personal slider, I stumbled upon a perplexing discovery. I encountered a CSS regulation that looked like this: html.js #slideshow .slides img { position: absolute; } The explanation suggested that ...