What is the best way to adjust the dimensions of an image using CSS?

I've been struggling to adjust the dimensions of my image using CSS by specifying a width and height attribute. However, instead of resizing the picture, it seems to simply zoom in on the existing image.

For instance, I have an image that is 90px by 90px. But whenever I modify the width and height values, it appears as if the image is just being magnified rather than becoming smaller.

My current CSS code looks like this:

.image-90 {
    horiz-align: center;
    width: 60px;
    height: 60px;
    background-size: 90px 90px;
    margin: 10px;
    border: 1px rgb(218, 218, 218) solid;
    background: #C4C4C4 no-repeat 0 0;
    background-image: url('/Content/images/person_noimage.png?width=90&height=90&mode=crop');
}

Below is the HTML segment where I'm trying to display the image (the URL is stored in Person.AvatarImage):

<div class="image-90" style="background-image:url-Person.AvatarImage"></div>

Answer №1

background-size should always be declared after background and background-image. While this may vary across browsers, I have personally observed it in Chrome and Firefox. Take a look at http://jsfiddle.net/WS2qe/1/

When setting just one value, the browser assumes it to be the width and adjusts the height automatically to maintain proportionality for the background.

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

When an image is loaded, use Jquery to automatically open a new tab, instead of

I need to implement a function where, on loading an image on a page, a new tab opens and starts downloading a file from a specific URL while keeping the original page open. This task is part of a WordPress site with a jQuery section in the backend. I' ...

Utilizing XPath to retrieve text from a hyperlink

I'm currently using Python with Xpath to scrape Reddit, specifically working on extracting links and displaying their titles on the front page. To do this, I'm utilizing the Scrapy framework and conducting tests in the Scrapy shell. I'm stru ...

Tips for utilizing both noConflict and $ on one page

Can I use both noConflict and $ on the same page? <p>This is a paragraph.</p> <h1>hello</h1> <input type="button" id="=mybtn2" value="jq" onclick="myfun2();" /> <input type="button" id="mybtn" value="$" onclick="myfun(); ...

Pop-Up Window Shifts Down after Initial Appearance to the Right

This code snippet demonstrates a popup that is intended to appear to the right of the question mark link once it is clicked. Check out the example here: https://jsfiddle.net/eur6ao3z/13/ Initially, the popup displays correctly on the first click. However ...

Toggle between a list view and grid view for viewing photos in a gallery with a

Hey there, I'm a newbie on this site and still getting the hang of jQuery and JavaScript. Though I do have a good grasp on HTML and CSS. Currently, I'm working on a photo gallery webpage as part of my school project using the Shadowbox plugin. Wh ...

Is there a way to move the cards to the next line within a wrapper when the screen size is reached?

My goal is to showcase multiple elements in cards, obtained from my routing system, much like how I'm setting up my sidebar (which is functioning correctly). I have all the titles and icons ready, and the linking works seamlessly. This is where I&apo ...

A method for determining the quantity of <li> elements within a <ul> container while applying specific conditions

I am currently using document.querySelectorAll('ul > li').length to count the total number of items in my list. However, I am wondering if there is a way to count only those items that meet a specific condition. For example: <ul> < ...

Is it possible to create a dynamic image in WordPress and have it automatically set as the background in the Style.css file?

I successfully transformed an HTML template into a WP theme and now I aim to add dynamic elements throughout. My first task is to make the slider (comprised of image, heading, content, button) dynamic. Currently, all the code resides in index.php except ...

"Struggling with getting the text color to change on hover in Tailwind

Today has been a frustrating day as I am diving into the world of tailwindcss and have been struggling with a particular issue. My code is below: <button className="bg-yellow-500 px-4 py-2 hover:text-black text-white"> Some Text Her ...

Leveraging XPATH to pinpoint objects based on their RGB background color

I have a table with multiple divs inside it, many of which are identical except for their background colors! Is there a way to select a specific div based solely on its background color? Here is an example of the HTML structure: <div class="fc-event fc ...

Looking for a way to track the number of visits your website receives using Splunk?

Examples I've attempted: "url" | stats count index="indexname" "url" |stats count Is it necessary to establish logging on my webpage before I can access the hit count? ...

Is jQuery failing to respond after being transferred from HTML to PHP?

The debug message from the Venkman debugger reads as follows: $("#aboutbox") is null [Break On This Error] $("#aboutbox").hide(); I'm at a loss on how to resolve this issue! It was functioning perfectly in HTML: But after transitioning it to PH ...

How do I activate validation within bootstrap4 using bootstrap-validate?

I am working with a validation form in Bootstrap4 that displays an error message when less than 5 characters are entered. If I enter 5 or more characters, I want to show a green check-mark and border around that specific input field. <div class="con ...

Troubleshooting problem with nested image carousel in Bootstrap modal

I am working on implementing a modal for displaying an image gallery. The initial modal showcases thumbnails, and upon clicking a thumbnail, a secondary modal should open on top with larger images displayed in a carousel. The issue I'm facing is that ...

Incorporating an external script within a Next.js application

I've been having trouble incorporating an external JavaScript source into my Next.js application and I keep encountering the following error: Failed to execute 'write' on 'Document': It isn't possible to write into a documen ...

divide the information within an HTML table cell

One way I have figured out to populate the cell of a table is by using the following code: {% for row in data %} <td> {{ row[4] }}</td> Now, let's say I have the data "['sugar']:['3642847']:['2020-08-21' ...

Decrease the size of the mat-flat-button

I have a message board where I am trying to incorporate delete buttons. However, when using the mat-flat-button feature, it appears to be increasing the height of the message items. If I adjust the button's height to 50%, then the button becomes half ...

How do you activate the background color for paragraphs <p> when a bootstrap button is styled with CSS?

In the code snippet provided below, dynamic creation of paragraphs with changing background colors and styles is demonstrated. One challenge faced in this script is maintaining the printed background colors for each dynamically generated paragraph. The is ...

Exploring the differences between two CSS style attributes using JQuery

Can someone help me with a quick question about CSS? I need to compare two style attributes, specifically margin-left. If the margin-left is less than 500px, I don't want to make any changes. However, if it's greater than 500px, I want to add ano ...

How to exclude elements nested inside another element using CSS or XPath techniques

Presented here is a snippet of XML code: <xml> <section> <element>good</element> <section class="ignored"> <element>bad</element> </section> </section> </xml> Identifying a ...