Limiting the background-size property to the size of the original image

I have a project where I am putting together a photo album, with the photos displayed within a div that covers the entire page. Here is the CSS code used:

.photoHolder {
    background-size: contain;
    background-image: url(theImage.jpg);
    background-position: 50% 50%;
    background-repeat: none;
    width: 100%;
    height: 90%;
    [...]
}

The issue I am facing is that when the original image is smaller than the photoHolder, it gets stretched and loses quality. Is there a way to prevent this stretching without resorting to using JavaScript to limit the size of the div?

It's important to note that both the photo sizes and the size of photoHolder can vary, as it takes up most of the available window.

Answer №1

To fix this issue, simply eliminate the following line:

background-size: contain;

This particular CSS property is what's causing the background image to appear stretched.

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

Guide to positioning social media icons and their tooltip within a navbar using Bootstrap4

I am struggling to align the social icons and their tooltips with the rest of my navbar. The issue is that the icons are not centered within the square, and their tooltips do not align correctly under the yellow box (although in other parts of the code, su ...

What is the reason that CSS clamp() does not function properly when using only zero without any units?

Check out my pen where I demonstrate a bug: https://codepen.io/dimakrutoo/pen/PoGZymb When the value of --layoutWMin is changed from "0px" to "0", it causes the calculations to fail. Why does the clamp() function not work with a zero value without units? ...

Disabling the navbar menu on Ruby on Rails occurs when pages are changed

I am facing an issue concerning the responsive navbar functionality on my website. The problem occurs when the screen width drops below 1024px. Initially, the navbar is designed to switch to a responsive mode upon clicking the burger menu, which is impleme ...

When I include a class in a checkbox label, the CSS ceases to function properly

Apologies for my lack of understanding, but I am facing an issue with applying an attribute to a label element with class "c". It seems to work fine with other objects, like buttons, but not with labels. I cannot figure out why such a simple thing is not w ...

Creating a React component with a circular loader that displays percentage and texts using Material-UI

I've developed a CircularLoader component using Material UI. The issue I'm facing is that when the variant is set to 'indeterminate', the loader should display without any percentage indication. However, if the variant is 'determin ...

A complete guide on utilizing *ngFor in Angular to display data rows

I am facing an issue with using *ngFor to create new "rows" for adding new categories dynamically. Although there are no errors displayed when I run the program, the intended functionality is not achieved. I have tried making some modifications but it see ...

Footer won't have the option to right align the Span element

I'm having trouble getting my copyright span to align to the right in my footer. Can you help me figure out what I'm doing wrong? <footer> <span>Blog</span><span>Hire</span><span>About</span><spa ...

The art of perfect alignment: Mastering the positioning of Material-UI Grid

This issue has been resolved Hey there, I'm currently working on a React App with Material-UI and I'm trying to center a Grid item that includes a Card along with two additional Grid items. Below is the relevant code snippet. Although the Cards ...

The make-xx-column() mixins in Bootstrap are malfunctioning

After careful examination, it looks like some of the Bootstrap mixins are not functioning as expected. Specifically, the .make-md-column() and .make-sm-column() seem to have no effect at all. Initially, I suspected that WebEssentials was not compiling the ...

What is the best way to align these JavaScripts side by side using div elements?

After searching many sources and attempting various methods, I am still struggling to position two lines of code side by side on my website. My attempted solution can be found at the bottom of the code. http://pastebin.com/mV1DUbg0 The code looked strang ...

What is the best way to decrease the horizontal gap between col-md-4 divs?

HTML <div class="container"> <div class="row"> <div class="col-md-4"> <div class="content">1x1</div> </div> <div class="col-md-4"> <di ...

What is the reason for the malfunction of input :: - webkit-slider-thumb and input :: - moz-slider-thumb?

Designing a compact slider for enhancing user experience not limited to webkit browsers requires utilizing a scss template such as input { width: 100%; -webkit-appearance: none; -moz-appearance: none; appearance: none; height: 1vm ...

Maintaining a child div with an aspect ratio of 16/9 to always fit within a parent div using CSS is proving to be a challenge

I am currently facing a challenge in adding a face overlay to an image while ensuring that the face remains within the inner div. The image is required to fit over a 16/9 ratio backdrop and also stay within the outer container. I have managed to achieve t ...

The `background-size` property in jQuery is not functioning as expected

I am facing the following issue: When I click on a div with absolute positioning, I want to animate its position, width, and height. In addition, I want to change the background-size using jQuery. However, the problem is that all CSS properties are updat ...

What is the best way to ensure that the sidebar appears after the content on mobile devices, even when there are full-width blocks within

I attempted to enclose fixed-width content and sidebar within a common container, but when it came to mobile devices, I could only come up with a solution where the sidebar is positioned after the content and before the full-width content. However, this ar ...

Different CSS Transform values are required based on the length of the text

I have created a demo that showcases 5 floating <div>s with rotated text of various lengths. Is there a way to implement a CSS class that can centrally align all text, regardless of length? Currently, I find myself creating a new class for each chara ...

Enhancing the input field in React with a custom wrapper and dynamic height adjustment

I'm attempting to create an input component that wraps the text and increases in height with each new line, similar to how it works on desktop Facebook. When you select someone, open the message box, and start typing, the input grows larger with each ...

What are some ways to ensure that my css moving image element is responsive on smaller screens?

Currently, I am working on an image that has a downward motion upon page load. However, the issue arises when viewing it on smaller screens as it doesn't appear. How can this be resolved? Here is the HTML code: <img class="logo" src=&quo ...

What is the best way to adjust the size of the box while ensuring that the text remains centered inside it

Consider the HTML snippet below: <div class='title'><h2>Title</h2></div> I attempted to adjust the size of the box with the following CSS: .title { display: block; border-radius: 12px; border: 1px solid; } The resultin ...

"Enhance the appearance with jQuery: beautifying code

In order to achieve a pretty print layout using jQuery and HTML, I need to ensure that if any div with the class .section reaches the bottom of an A4 page (where the A4 body width is 595px and each page height is 842px), it will have a margin added to push ...