I prefer images to remain static in size while adjusting the browser dimensions

On my webpage, I initially specified the sizes of images in pixels like this:

<IMG src="image.png" width=700px height=100px>

However, when viewed on machines with different screen resolutions, the page didn't always display as intended.

To address this issue, I switched to using percentages for image dimensions instead, like so:

<div class="logo_container">
  <IMG src="image.png">
</div>

and

.logo_container img {
    padding: 15px;
    width: 37%;
    position: relative;
}

While this adjustment made the page appear correctly, I noticed that when resizing my browser window, the images would shrink while maintaining their aspect ratio. This was not what I wanted.

I aim for the web page to maintain its appearance at full screen but without the images shrinking unnecessarily.

Thank you.

Answer №1

To optimize your website's display, adjust the CSS according to the screen width:

<div class="logo_container">
  <IMG src="image.png">
</div>
<style>
@media screen and (max-width: 540px) {
    .logo_container img {
        padding: 15px;
        width: 100%;
        position: relative;
    }
}
@media screen and (min-width: 540px) and (max-width: 780px) {
    .logo_container img {
        padding: 15px;
        width: 50%;
        position: relative;
    }
}
@media screen and (min-width: 780px) {
    .logo_container img {
        padding: 15px;
        width: 30%;
        position: relative;
    }
}
</style>

Answer №2

Utilize em units.

<img src="" alt="">

CSS:

.logo_container img {
    width: 1em;
}

The beauty of em units is that they remain consistent across all devices, maintaining the same size in real life. For more information, visit https://www.w3schools.com/cssref/css_units.asp.

Answer №3

To make the image a specific width, simply define its size in pixels:

.logo_image img {
    width: 300px;
}

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

Building a loading bar using dots

<span class="dot"></span> <span class="dot"></span> <span class="dot"></span> <span class="dot"></span> <span class="dot"></span> <span class="dot"></span> <span class="dot">< ...

How can you enhance the visibility of AngularJS Materials dropdown menus?

While experimenting with AngularJS Materials, I noticed that the text in some elements like <md-input-container> and <md-select> may be too light for some people to read easily. I wanted to find a way to make the text more visible without chang ...

What is the most effective way to attain maximum height for this particular element?

Is there a way to make the height of the left-div 100% of the window's height? <div id="left-div"></div> <div id="content"> <div class="thumbnail"></div> <div class="thumbnail"></div> ...

Retrieve multiple data sets

Here's the code I'm currently using, it pulls a random profile picture along with the user's first and last name. It works great, but how can I make it pull more than one at a time? $query = $db->query("SELECT * FROM `content` ORDER BY R ...

Transfer a characteristic from one element to another

I need help with multiple columns of checkboxes and labels. <ul class="column1"> <li> <input value="jan" type="checkbox" /> <label>Jan</label> </li> <li> <input value="feb" t ...

Form for contacting with file attachment option

I'm having trouble integrating file upload functionality into my existing code. I've been scouring the internet for solutions but haven't found anything that fits seamlessly with my current setup. It's frustrating to encounter error aft ...

Certain HTML code on a webpage is currently inaccessible to me

Struggling with web scraping on a webpage due to inaccessible code. The part of the page's code that remains out of reach is only accessible through an anchor tag, with the following html: <a class="MTLink" href="#d192633539-47" title="example" &g ...

- "Queries about Javascript answered with a drop-down twist

Having some trouble with setting up a straightforward FAQ dropdown feature. Could someone lend a hand and see what might be going wrong? Appreciate your help! CSS #faqs h3 { cursor:pointer; } #faqs h3.active { color:#d74646; } #faqs div { height:0; o ...

When a button is clicked, the event is not triggered within a FirefoxOS application

Despite functioning perfectly on Firefox for desktop, my application encounters issues when tested on my ZTE Open C (Firefox OS 1.3). Pressing the button does not trigger any action, while onmouseup and onclick events work flawlessly. Even attempts to bin ...

Enhancing user experience by implementing AJAX in a contact form to eliminate the need for page

I have read numerous questions on this topic and have compiled the code I currently have from various responses. Unfortunately, despite my efforts, I am unable to make it work and I cannot identify the reason behind this issue. Below is the HTML form str ...

Steps for loading a new page by clicking an input button:

I'm looking for some help with a basic issue I'm having while customizing a WordPress plugin. I want to redirect the user to the thankyou.php page when they click on the place_order button. I tried changing the input value to thankyou.php, but it ...

Is it possible for links to remain clickable even if they pass underneath a div

I have implemented a shadow using a div element to cover some content beneath it. However, I am facing an issue where the div that is under the shadow cannot be interacted with. Is there any solution to this problem? Thank you ...

Receiving an empty response for the radio button selected

Having some trouble retrieving the checked radio button in my PHP via Post method. Despite using validation and submitting the form through JavaScript, I'm not getting any value. Can anyone point out where I might be messing up? Let me know if you nee ...

Steps to remove a scrollbar from a fullscreen slider

Can anyone provide code examples on how to disable the scroll bar on a full screen slider? I want to have a scroll down button on each slider that, when clicked, will show the scrollbar only below the slider. I don't want the scrollbar to be visible ...

A single feature designed to handle various elements

I currently have this HTML code repeated multiple times on my webpage: <form class="new_comment"> <input accept="image/png,image/gif,image/jpeg" id="file" class="file_comment" key=comment_id type="file" name="comment[media]"> <spa ...

Exploring ways to create additional file upload fields with distinct names through JavaScript

My latest project involved creating a button that allows users to add a file upload field, a separate button to remove a file upload field, and a counter to keep track of the total number of file upload fields. However, it appears that the fields are not b ...

How can I easily tailor Google Map designs for embedding on websites using iframes?

How do I customize the color of Map attributes within an iframe? <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3929.7682222383455!2d78.13052821529986!3d9.95323247656748!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x3b00c5e0 ...

Detecting single letters in a sentence and changing their appearance using CSS

Looking to make a subtle change to text? I need to swap out single letters in a passage (I have a cat that ate a fish). Any ideas on how to do this? The goal is to input a block of text into a textbox, then display it in a div. I've had difficulty fi ...

Horizontal Scroll HTML

Currently in the process of building a website for my father, everything is going smoothly. I followed a helpful Stackoverflow tutorial to create a specific webpage that I now want to customize with a hyperlink and make it scroll horizontally: Sliding divs ...

Pictures failing to display in their designated location

Having trouble with my social media icons on the page. They either get hidden by other divs despite having a higher z-index or appear below the top section. I want them to be positioned to the right of the church image. I've tried different approaches ...