Adjust the size of the image to match the dimensions of the div

Whenever I try to adjust the size of the image inside the div element, it doesn't seem to change. The div itself functions properly, but the image remains fixed in size.

Is there a way to scale the image proportionally when resizing the div?

div.column {
    display: block;
    position: relative;
    max-width: 800px;
    margin: 0 auto;
}

div.fixedratio {
    padding-top: 100%;
    display: block;
    position: relative;
    margin: 0;
    background-color: #eee;
    background-image: url('http://i.imgur.com/4pgtZwz.png');
    background-size: cover;
    -moz-background-size: cover;
    background-position: center;
    border: 1px solid #999;
    background-position: center center;
}

.tengah {
  left: 50%;
  top: 50%;
  position: absolute;
  margin-top: 0;
  margin-left: 10px;
}


<div class="column">
   <div class="fixedratio">
      <div class="tengah">
           <img src="http://s9.postimg.org/5ocnzd117/icon_player_soccer.png">
      </div>
   </div>
</div>

http://jsfiddle.net/jeffernandes/f05jh0gs/4/

Answer №1

To ensure the image scales proportionally with the div when it is resized, consider utilizing the background-size:contain CSS property.

Answer №2

To modify the size of the images, you should incorporate some CSS coding like the following:

.center img{
 width:55%;
 height:55%;
 }

By doing this, the image's width will be adjusted to a percentage based on the dimensions of the parent container.

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

Tips for positioning a div element at the center in ASP.NET

I have written the following code snippet: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Main.aspx.cs" Inherits="Main" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transit ...

Ways to create CSS styles dynamically in PHP using database-driven methods

Currently, I am in the process of developing an application that gives users the ability to select different style options within the app. These choices will then be utilized to create a dynamic web page. I am curious about the various methods available to ...

Troubleshooting Bootstrap's Margin Problem

Currently, I am delving into the basics of bootstrap and encountering some challenges with using margin-auto. Specifically, I am working on positioning a navbar by using ml-auto to separate it from the brand, pushing the navbar to the right side of the p ...

Tips for displaying the number of selected values in a select box label (e.g. Choose an Option)

I am currently using the jQuery multiselect API in my application to allow users to select multiple values. However, I am facing an issue where I need to fetch all the selected values when a button next to the multiselect box is clicked. Unfortunately, I h ...

How to ensure a list item remains in a fixed position when resizing the window

Imagine a scenario where there is an unsorted list within a resizable div element. The list is set up horizontally and aligned to the right, with one item designated as "special" and given the id="pinned". Using only CSS, can you keep the #pinned item in ...

Bootstrap allows for the creation of five columns of equal width that span the full width of the container

My PSD template includes a CONTAINER with 5 equal width columns measuring 344px each. I initially opted for Bootstrap to handle responsiveness, but now I'm feeling overwhelmed by the task. Is there a way to tackle this issue, or should I: Revise my ...

Modal at the bottom half of a React web page

Currently working on developing a responsive app with React JS and in need of a modal component for the bottom half. A similar feature can be found in react-native-modal. Also utilizing material-ui, unsure if I can customize the modal dialog to achieve th ...

Alignment within bootstrap using accordion

I am new to using bootstrap. Currently, I am creating a simple FAQ page with bootstrap and facing some challenges. https://i.sstatic.net/6fUW3.png I have been trying to adjust the position and margin of elements, but I am struggling to center the title a ...

Transferring content files from a nuget directory to a specific destination folder

I am dealing with a nuget package that includes css files as content. My goal is to have these css files copied to a specific directory upon importing the package into a project, without requiring the project's structure to match exactly. Is there a ...

Images that dynamically adjust within the confines of a single div

My issue involves a simple script that includes two responsive images. When the window is minimized, the images adjust accordingly. However, when I place both images within the same div like this: <div class="wrapper"> <div class="block"&g ...

Creating visually appealing Highcharts.js visualizations for both mobile and desktop devices

Has anyone had success implementing a responsive design with Highcharts to ensure charts look great on both mobile and desktop screens? By default, Highcharts do adjust when resizing the browser window, but sometimes the X-axis can become cluttered by tic ...

Mobile viewing causing problems with website buttons functionality

While my website functions perfectly on desktop, I am facing an issue where the buttons are not working when accessed through mobile devices. Interestingly, these buttons were operating fine in a previous version of the site. Although I have made minimal ...

Having trouble displaying image using absolute path in Express

Currently, I am developing a NodeJS application and have encountered an issue with a div element that has a background-image set in an external CSS file. Surprisingly, the CSS file functions perfectly when tested independently, and the background image dis ...

Position the div beneath another div using the display:grid property

I can't seem to figure out how to position a div below another div using display:grid. The div is appearing on top instead of below. The "app-bm-payment-card-item" is actually a custom Angular component. Here's the HTML file: //div wrapper < ...

Tips on connecting a font directory from FontAwesome

I am currently attempting to incorporate the fonts provided by FontAwesome for their icons, and they specify that a root folder named Fonts is needed. My attempt to link it was using: <link type="text/css" href="/myPath/font" /> ...

Do you think there might be an issue with the CSS coding?

I have designed a user-friendly responsive login form that allows users to easily log in and reset their passwords. However, I am facing an issue where the username and password fields are not displaying on separate lines as intended. I have thoroughly ins ...

"Basic npm module that does not come with any CSS code, featuring a React component that

I am working on developing a small and straightforward npm package that leverages react. The challenge I'm facing is the need to import the CSS file from the dist folder and have it automatically imported with the export. Is this achievable? import Re ...

Stacking two divs for the team section layout

Although I'm new to this, I've been struggling to achieve a specific layout for a team page. My goal is to display a picture on the left side and text on the right for each team member. The design includes the person's name, title, and a set ...

Having trouble with Vue.js implementation of Bootstrap tab navigation?

I am currently working on a vue.js application that consists of 2 routed components. I recently attempted to integrate a bootstrap tab navigation into the first component, but unfortunately, the tab contents are not being properly displayed. <templat ...

The impact of empty space on design aesthetics and practical solutions to utilize white space effectively

Within this example <html> <head> <style> .q_show_spaces { white-space: pre-wrap; } .q_inline { display: inline; } .q_no_wrap { white-space: pre; } </style> </head> &l ...