Unable to adjust the dimensions of the image

I recently added two images to my website successfully, but I am facing an issue when attempting to modify their dimensions and shape using CSS. Despite adjusting the height, width, border-radius, etc., the images remain unchanged. Can anyone provide insight into what might be causing this problem?

Here is a snippet of my HTML code:

   <div class="tile-image"></div>
   <div class="tile-image"></div>

This is the relevant portion of my CSS code:

   .tile-image {
    width: 432px;
    height: 192px;
    object-fit: cover;
    border-radius: 4px;
    }

Lastly, here is how I am handling it in JavaScript:

 data = {
 "tiles" : [
 {
 "img" : "example.jpg"
 },
 {
 "img" : "example.jpg"
 }
 ]
 };

data.tiles.forEach((item) => {
let img = new Image();
img.src = item.img;
tile = document.getElementsByClassName("tile-image")[0];
tile.appendChild(img);
});

Answer №1

If you want your image to fit the container perfectly, adjust the width accordingly.

Here is a CSS snippet you can use:

.tile-image img{
   width: 100%;
}

Alternatively, if you have specific dimensions in mind for your image, consider this approach:

.tile-image img {
   width: 432px;
   height: 192px;
   object-fit: cover;
   border-radius: 4px;
}

Answer №2

Make sure to apply the height and width directly to the images, not just the parent div. Try incorporating this CSS:

img {
  max-width: 100%;
  max-height: 100%;
}

This adjustment should resolve your issue.

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

Prompt for confirmation in ASP.NET code-behind with conditions

I've searched around for a solution to this problem. Below is a representation of my pseudocode: bool hasData = ItemHasData(itemid); Confirm = "false"; // hidden variable if (hasData) { //Code to call confirm(message) returns "true" or "false" ...

URL from different domains

Currently, I am attempting to utilize this URL within my javascript code: Below is the snippet of my javascript code: $.ajax({ url: 'http://api.addressify.com.au/address/autoComplete', type: 'GET', crossDomain ...

Tips for resolving a jspdf naming collision situation

In my react app, I am utilizing various jsPDF libraries as shown below: For exporting tables as HTML: import jsPDF from 'jspdf'; import "jspdf-autotable"; For converting SVG to PDF: const svg2pdf = require('svg2pdf.js'); con ...

What is the best way to obtain the value of a radio button using ajax?

Here is the search button in my PHP file. I am unsure of how to connect the radio button to the JavaScript file. <button id="submit">Search</button> This is the starting point in the JavaScript file var xhr = new XMLHttpRequest(); f ...

Ways to provide information to an rxjs observer

It appears that most people find observers to be a piece of cake, but I personally struggle with them. I am trying to set up an observable that can receive a number input after it has been created, triggered by pressing a button. However, all the examples ...

Verify user using Cognito user pool log-in information

Is it possible to authenticate a user using only user pool credentials without an identity pool/IdentityPoolId? Check out this link for more information: https://github.com/aws/amazon-cognito-identity-js The example provided in the link above specifically ...

What is the best way to assign three different dates in my protractor test?

I am facing an issue with setting random dates in 3 date fields in a row using Protractor. The problem is that Protractor sets the dates too quickly and sometimes assigns invalid dates like: first data: 01/08/1990 (correct) second data: 01/09/0009 (inva ...

When I scroll, changing the position from fixed to absolute causes my image to jump

My goal is to implement a unique visual effect where a background image, initially positioned as "fixed", gradually moves towards the top of the webpage and then disappears as if it were absolutely positioned. However, this movement should only occur after ...

Customizing Form Inputs in ReactJS using Props Array

Trying to wrap my head around handling a dynamic number of props data for a form. Despite searching high and low on Google, I've come up empty-handed. I am gathering data on the number of appointments based on the number of dogs owned by a user. So, t ...

Tips for displaying bar chart labels effectively with ChartJS

I am working on an Angular project and I would like to incorporate a barchart using ChartJS. The data for this chart can vary in size, sometimes being very large. One issue I have encountered is that when the number of data points is large, the labels ove ...

Attempting to create a lineup of bricks with varying widths that are directly related to the overall width of the canvas

I'm attempting to create a row of randomly sized bricks on a canvas. The bricks should have varying lengths, but must stay within the confines of the canvas. The canvas has a length of 400, and I want there to be a 10px padding on each side between ...

Special html effects for scrolling

Recently, I've been noticing a trend of websites incorporating new and innovative scrolling effects. One great example is: As you scroll down the page, the initial section stays fixed in place (z-index of 1?) while the content scrolls over it seamles ...

Choose all elements following the first child element

My goal is to create a LESS rule that targets every element following the current element, excluding the first child. I've tried using this syntax: (& ~ *):not(:first-child) { margin-left: 5px; } and also this one: & ~ *:not(:first-child ...

Struggling to incorporate JSON data and javascript functions into an HTML file

I've been struggling to create a feed from a json link and display it in separate divs within an html document. Despite multiple attempts with different approaches for three different newspaper sources, I have not been successful. I'm hoping som ...

How to dynamically generate <select> <option> elements in VueJS using the v-for directive

Just started exploring VueJS and I recently learned how to use a v-for loop to populate a Select Options box. <select> <option v-for="person in persons" :value="personid">{{ personname }}</option> </select> ...

How is it possible that my array becomes reversed without any intervention on my part?

As I work on developing a website, I encountered a puzzling issue with the calculations inside the router. Despite initializing the array tomato with the desired values, it seems that the values get reversed just before rendering the page. Here is the code ...

The Angular expression has been modified after being examined

I've encountered a common error in my Angular application, but I'm struggling to pinpoint why it's happening and how to resolve it. I've attempted various approaches such as using setTimeout, delay(0), and switching to different hooks, ...

I am looking to dynamically generate HTML elements using AngularJS based on data from a JSON file

Although there are existing answers to this question, I have a specific approach that I need help with. I've already made progress but could use some guidance. This is my Controller : angular.module('dynamicForm.home-ctrl',[]) .con ...

What are the possibilities of utilizing a variable that is stated within composition to enable dynamic rendering?

I'm working on a Vue.js v3 project using the composition API. I have defined a variable in my setup like this: setup() { const showInvoiceItemForm = true; return { showInvoiceItemForm }; }, Now, I want to show a form when a button is click ...

Learn the process of using Angular Js to compare checkbox values with stored comma-separated values in a database

When displaying amenity checkbox options using ng-repeat of a JSON array and saving them into the database as comma-separated IDs like "1,3,7" within a single string, the challenge arises when needing to edit the amenities. This is due to retrieving the ex ...