Is it possible to adjust the size of my image based on the browser's zoom level?

While working on my website, I noticed that when I zoom out on my browser, everything resizes except for the image. The image remains the same size regardless of whether the browser is set at 100% or 50%. Is there a way to code the image so that it resizes according to the browser's zoom level?

This website is built using HTML5, CSS, and JavaScript. The image is rendered using JavaScript.

function get_attrs() {
  // change the avatar as needed
  if (convStyle == 'dominant') {
    $("#robo-image").attr("src", "images/avatar/D-Robo.png");
    $(".user-description").prepend("<h3>Max</h3>");
  } else if (convStyle == 'submissive') {
    $("#robo-image").attr("src", "images/avatar/S-Robo.png");
    $(".user-description").prepend("<h3>Linus</h3>");
  }
}
.robot-section {
  overflow: hidden;
  padding: 3rem 0 3rem 2rem;
  /*padding: 3rem 0rem;*/
}

.robot-section {
  overflow: hidden;
  padding: 3rem 0 3rem 2rem;
  /*padding: 3rem 0rem;*/
}

.robot-content-bottom {
  overflow-x: hidden;
  overflow-y: auto;
  max-width: 100%;
  /*position: absolute;*/
  /*bottom: 5%;*/
}
<div class="col-sm-6 col-md-4 col-lg-3 robot-section">
  <div class="robot-content-top">
    <div id="messageContainer"></div>
  </div>
  <div class="robot-content-bottom text-center">
    <img id="robo-image" alt="avatar" class="avatar-img">

    <div class="user-description">
      <h4>Your personal financial advisor</h4>
    </div>
    <!--<div class="user-description">-->
    <!--&lt;!&ndash;<h3 style="margin-top: 30px;">Ethan</h3>&ndash;&gt;-->
    <!--&lt;!&ndash;<h5>Your personal financial advisor</h5>&ndash;&gt;-->
    <!--</div>-->
  </div>
</div>

Answer №1

It seems like the issue you are facing is related to specifying width or height using percentages.

When you set the width to a percentage (100%), the image will always occupy 100% of the browser width and won't adjust with scaling.

An image with fixed dimensions will resize accordingly, but an image with a percentage-based width will not be affected.

<img id="image" src="" width="622" height="350">
<img id="image2" src="" width="100%">

You can see an example on jsfiddle.

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

Can we retrieve props that have not been explicitly passed down?

How can I access the prop "showPopover" from the constructor or another method? This prop was originally created in a separate component and now that I've integrated it into this component, I'm looking for a way to easily retrieve and modify it. ...

Creating a Clickable SVG Element in React

I've been attempting to set up an onClick event in React, specifically within an SVG that includes multiple circle objects. However, when using "onClick," I'm encountering a strange issue: Upon data load, the onClick event is triggered six times ...

Tips for removing the default CakePHP CSS without deleting it from the default.ctp file

Currently, I am looking to enhance the design of my webpages individually using Bootstrap. The specific page I am focusing on currently utilizes the cake.generic.css stylesheet, but I am aiming to eliminate it from this particular page. Is there a way for ...

Deprecated as it may be, I am still determined to add an array of routes to my Vue router

In my Main.js file, I am currently fetching routes from the database using an API call. However, I've run into an issue with Vue router version 4 deprecating the addRoutes functionality. Now, I can only add one route at a time which is not ideal for m ...

What is the technique for accessing dynamic object properties in Javascript?

I am dealing with a dynamic object where the property values change based on different data sets. For example: MyObj = { country:"Ind", Place:"Pune"} Now, I have a data value that determines which property value I need to retrieve. var MyArr = this.Filt ...

Get rid of the border surrounding the JavaFX ScrollPane scroll bar when it is not in focus

I'm experiencing a quirky problem. I've customized the scroll-bar of my ScrollPane in JavaFX with CSS, but there's a strange behavior where the border disappears whenever the ScrollPane is in focus. However, if I interact with a button outsi ...

Divide the array into distinct characters or verify the presence of a specific character

I have designed 3 buttons with unique names. When button A is clicked, it appends the value to an array. For example: <a href="#" class="answer" data-value="Football">Football</a> Clicking on this button will add "Football" to an empty array. ...

Using jQuery to upload a file by reading from the local device

I am attempting to upload a file using jQuery in pure JavaScript by reading the file from a local path. The typical approach involves fetching the file from an HTML input and appending it to FormData. var formData = new FormData(); formData.append("test", ...

Utilize the power of Javascript/AJAX or jQuery to submit multiple forms simultaneously

I am currently working on a project which involves having 3 forms on a single page. The reason behind this is that one of the forms is displayed in a modal dialog. My goal is to allow users to submit all 3 forms with a single button click, and I also wan ...

Leveraging both closetag.js and closebrackets.js simultaneously in Codemirror on a single line

Currently, I am integrating the Codemirror library with a textarea to enable autoclosing of HTML tags and brackets such as {}, (), []. However, I have come across an issue where they do not work together on the same line. For example, when typing out a ta ...

Exploring the Unpredictable Results of Recursive Functions in JavaScript

Take a look at this recursive code snippet. function calculateFactorial(n) { if (n === 0 || n === 1) { return 1; } else { console.log(calculateFactorial( (n - 1) )); return n * calculateFactorial(n - 1); } } const num = ...

Having trouble receiving any ringing status in nextjs while utilizing the getstream SDK

I attempted to integrate the getstream video SDK for calling from the caller to the callee. While I can successfully create calls from the caller side, I am not receiving any status updates about the call on the callee side. Below are my codes for the cal ...

h1 text obscured by video backdrop

Having trouble with a h1 tag appearing behind my video element. I'm fairly new to programming so please excuse any ignorance on my part. I attempted to overlay a header on top of a video, but it was unsuccessful. I've also experimented with z-in ...

Encountering difficulty in implementing two modals simultaneously on a single web page while utilizing the useDisclosure() hook in Ch

ChakraUI provides a custom hook called useDisclosure() which gives you access to isOpen, onClose , onOpen. const { isOpen, onOpen, onClose } = useDisclosure() You can use the onOpen function as an onClick handler for a button to open a modal. <Modal ...

order in which child objects are drawn

Encountering the following issue: I am attempting to create rings around Saturn, but they appear to be rendered in an incorrect order: https://i.sstatic.net/rVg3H.jpg The problem lies in how each planet is constructed. Each planet is a child of a differ ...

Can a Javascript function be passed an endless array?

I'm curious if there's a way to generate an array that can be infinitely long. For example, if I have a function like `arr(2,3,4,5,6,7)`, is there a command that would allow me to treat those numbers as an array and automatically extend the table ...

Adjust the Vue.js required property to allow null values but not undefined

I need my component to accept both objects and null values, as Vue.js considers null as an object. However, I want the validation to fail if the value is undefined. Here's what I've attempted using vue-property-decorator: @Prop({ required: true ...

The jQuery replacement should only be implemented on the new select box and not on the previous one

Let me illustrate the situation. I have a website and my aim is to gather information about the "Type of Business" for members on the site. I present all the current businesses that have been entered and allow users to choose one from the list. If a user w ...

What could be causing angularjs to malfunction in this specific scenario?

Recently, I followed a tutorial and implemented the code provided. Inside the angular folder in my libs directory, I have the minified version of Angular JS obtained from https://angularjs.org/. However, the output I am seeing is: {{author.name}} {{autho ...

extracting a HTML element from a website using BeautifulSoup

Image description is: https://i.sstatic.net/m4gxX.png Tag is: https://i.sstatic.net/skHQc.png I attempted to extract data from the stock dropdown menu but encountered a problem while trying to access the information. I identified the tag in the source ...