Struggling to format a responsive CSS background image

I'm facing an issue with setting responsive dimensions for a background image within a div that displays differently on mobile. Currently, I am manually specifying the width and height, but I want to avoid doing so. When I try using 100% for the width and either 100% or auto for the height, the image fails to display.

Here is the markup:

<div id="mts-popup" class="white-popup mfp-hide wow slideInDown animated" data-wow-duration=".5s">
<h2>MTS Collective</h2>
<div class="left-half">
<div class="popup-screenshot" id="mts-screenshot"></div>
</div>
</div>

And the CSS:

.white-popup {
  position: relative;
  background: #fff;
  padding: 20px;
  width: 100%;
  max-width: 1160px;
  margin: 30px auto;
  border-radius: 5px;
  text-align: center;
}
.white-popup .left-half, .white-popup .right-half {
  margin: 20px;
}
.white-popup .left-half {
  width: 50%;
  float: left;
}
.white-popup .right-half {
  width: 40%;
}
.white-popup .popup-screenshot {
  width: 600px;
  height: 456px;
  background-size: 100% 100%;
}
.white-popup #mts-screenshot {
  background-image: url("../img/portfolio/mts-browser.png");
}
div#mtsm-popup .left-half {
  width: 30%;
}

Any assistance on resolving this issue would be greatly appreciated!

Answer №1

The reason it isn't displaying an image is because it lacks defined width and height dimensions. Once you assign these values, the image will appear.

  .white-popup #mts-screenshot {
     background-image: url("../img/portfolio/mts-browser.png");
     width:200px;
     height:200px;
  }

Answer №2

Include additional background attributes such as background-position, bg-repeat, bg-color, or use the shorthand property for background.

Specify,

.white-modal {
    width: 1160px;
    max-width: 100%;
}

Answer №3

Upon examining your code, it appears that you have correctly set your parent container, .white-popup, to position:relative, which is a good practice. To enhance the layout, consider setting your left-half and right-half elements to position:absolute. By adjusting their positions in relation to .white-popup, you can maintain their positioning within the parent container. For example, you could experiment with values like left: 2%, top: 10% for .left-side and left: 55%, top: 10% for .right-side, both with a width of 40% or similar. Feel free to customize these values until you achieve the desired layout.

Wishing you success in your design endeavors!

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

Chrome does not support CSS animation rotation over 360 degrees

After researching for hours, I've encountered an issue with my animation in Chrome. It seems that while transform: rotate(1080deg); works flawlessly in Firefox, it fails to rotate in Chrome. Surprisingly, I discovered that it only rotates in Chrome wh ...

Table with Typewriter Style CSS Animation

I came across an interesting typewriter effect implementation using CSS in an article on CSS Tricks I decided to play around with it and see if I could apply it to a hero image, which I found an example of on Codepen However, I noticed that the blinking ...

Having trouble with the visibility of the hover background?

I have a goal in mind: This is the outcome I've achieved so far: LINK My aim is to have a white background with a blue border appear at the bottom when hovering over navigation links. Unfortunately, this isn't happening as expected. Can anyone ...

Combine jQuery and CSS to create a scrollable and extended fixed header

I am experiencing an issue where the header is fixed when scrolled down, but when I scroll back up to the top, it detaches and becomes unfixed again. How can I make the header stay fixed for a prolonged period of time? Are there any specific adjustments I ...

Retrieve the complete HTML content of a webpage, including the values of all input fields

I'm attempting to save the entire webpage as an HTML file, including all previously entered values in input fields. I have already tried this method: $("#content").html(); However, it does not retain the values entered into input fields. $("#conten ...

The menu shifts position or overlaps next to the current active menu option

It would be helpful to take a look at the URL provided (http://ymm.valse.com.my/) in order to understand my question better. Upon clicking on any menu item, I noticed that the menu next to the active tab overlaps. I believe the issue lies in the width pro ...

Display or conceal a div when hovering over dropdown menu choices

$('#dropdown-list').on('change',function(){ if( $(this).val()==="option 1" ){ $("#diva").hide() } else { $("#divb").show() } }); The code above is being used to hide or show a div based on a dropdown selection, which is f ...

Toggle between bold and original font styles with Javascript buttons

I am looking to create a button that toggles the text in a text area between bold and its previous state. This button should be able to switch back and forth with one click. function toggleTextBold() { var isBold = false; if (isBold) { // Code t ...

Ways to identify if a resize event was caused by the soft keyboard in a mobile browser

Many have debated the soft keyboard, but I am still searching for a suitable solution to my issue. I currently have a resize function like: $(window).resize(function() { ///do stuff }); My goal is to execute the 'stuff' in that function on ...

Obtaining <script> and <div> elements from Plotly with Python

Seeking advice on the best way to extract <script> and <div> tags from the HTML output generated by Plotly's offline client. Ideally looking for a built-in method, but open to creating a custom solution if needed. I have experience with B ...

Library for HTML styling in JavaScript

Is there a reliable JavaScript library that can automatically format an HTML code string? I have a string variable containing unformatted HTML and I'm looking for a simple solution to beautify it with just one function call. I checked npmjs.com but co ...

Verify if an item is currently within the user's view

I'm encountering a new issue with a menu I'm working on. My goal is to hide the menu when the user clicks outside of it. The challenge lies in the fact that the menu is always visible but translated to the right of the element, making it not dire ...

Guide on converting a JSON containing nested JSONs into an HTML table

Currently, I am working with a JSON data structure that contains nested dictionaries. My goal is to create an HTML table where each top-level key serves as a column in the table. The inner key-value pairs should be represented as a single text within cells ...

Using JQuery to automatically scroll and anchor to the bottom of a dynamically populated div, but only if the user doesn't

I am attempting to achieve the functionality of automatically scrolling to the bottom of a div with the ID #chat-feed. The overflow for this div is set to auto, and I want it to remain at the bottom unless a user manually scrolls up. If they do scroll up, ...

Mistake in the hovering positioning within the WordPress theme

I've encountered a hover issue on my website that I'm trying to resolve. Every time I hover over a product, the product description appears underneath it instead of on top, and I can't seem to find a solution: The site is using the sentient ...

Ways to extract all hyperlinks from a website using puppeteer

Is there a way to utilize puppeteer and a for loop to extract all links present in the source code of a website, including javascript file links? I am looking for a solution that goes beyond extracting links within html tags. This is what I have in mind: a ...

Ways to automatically choose an option based on the value of another dropdown?

I need help with a dynamic dropdown feature. Essentially, I have three dropdown menus and I want the third one to update based on the selections made in the first two. For example, if "M" and "Red" are selected in the first two dropdowns, then the third dr ...

Having issues with Bootstrap 5 modal not functioning correctly?

I'm facing an unusual issue that I'm struggling to resolve. I'm currently utilizing Bootstrap 5 and encountered the following problem: const reportBtns = Array.from(document.querySelectorAll('.report')) reportBtns.forEach((btn) ...

Using custom fonts in HTML on Bootstrap is causing issues

After struggling with a persistent problem for quite some time, I decided to delete my initial question since I was already utilizing Bootstrap. However, I am facing an issue where my custom fonts are not being loaded even though my main.css and bootstrap. ...

I can't seem to figure out why this file upload error is happening. What could be the

Having trouble with a simple file upload function and keep getting an "Error" message when trying to use it. Here's my HTML file: <form enctype='multipart/form-data' action='upload.php'> <input type='file' name ...