Images that adapt to different screen sizes

I'm not seeking a revolutionary way to handle the images, as I have already consumed a lot of information about loading images.

My focus is on basic responsive design, where I aim to load a large image and compress it as the window size reduces.

Below is the CSS code I have written:

@media (max-width:420px){
     #header #logo{
        width:60%;
        float:left;
        background:red;
    }

    #header #logo #image{
        margin:5%;
        width:20%;
        float:left;
        background:green;
    }

    #header #nav{
        width:40%;
        float:left;
        background:purple;
    }

    #header #nav #search{
        max-width:33%;
        float:left;
    }

    #header #nav #account{
        max-width:33%;
        float:left;
    }

    #header #nav #menu{
        max-width:33%;
        float:left;
    }
 }

Here is the accompanying HTML:

<div id="logo">
        <div id="image">
            s
        </div>
    </div>
    <div id="nav">
        <div id="search">
            <img src="assets/images/mobile-search.png"/> 
        </div>
        <div id="account">
            <img src="assets/images/mobile-account.png"/> 
        </div>
        <div id="menu">
            <img src="assets/images/mobile-menu.png"/> 
        </div>
    </div>

The challenge I am facing is that the images are not resizing as the window is resized. What is the correct CSS syntax to achieve this?

Thank you :)

Answer №1

To ensure your images display properly, add the max-width property to them.

img {
    max-width: 100%;
}

For a live example, check out this link: http://jsfiddle.net/VBHhD/

In my opinion, using an unordered list for navigation is also a good idea.

Answer №2

Within your CSS, there is a media query set for a maximum width of 420px, indicating a mobile view. Have you experimented with resizing your browser to very low levels to test this? @media (max-width: 420px){ #header #nav #search img,#header #nav #account img,#header #nav #menu img { width:50%;

} http://codepen.io/anon/pen/kchqg

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

Trouble adjusting the width of the Bootstrap card-body

After exhausting all available resources such as documentations and Stack Overflow answers, I am still unable to resolve the issue. Here is a snippet of the code I have tried: <meta name="viewport" content="width=device-width, initial-sca ...

If the PHP upload process is complete, restart the form

Is there a way to refresh my form or page after uploading a file without any issues? I want to clarify that the HTML file is stored in the root directory and the PHP file is stored in root/php/upload_action.php Below is my HTML code: <form enctype="mu ...

What is the best way to assign a class to a child element when the rest of the children are not visible

Looking for a CSS-only solution, I have a simple task involving filtering div elements. The goal is to display an error message when none of the filtered divs match the selected criteria. HTML Structure: <div id="listHolder"> <div class="lis ...

Creating a water vessel design using CSS

Despite going through the JS tutorial, I still struggle with it and need some assistance. I believe using a jsfiddle would be helpful. I am attempting to use JS to create a small box that changes color from green to empty based on the fullness of a "wate ...

JS How can I generate individual buttons in a loop that trigger separate actions?

Currently, I am working with loops in jQuery to create a series of boxes that contain specific values. The problem arises when I try to assign actions to each box based on the values from an array. For example, I want each box to trigger a different alert ...

Can you explain the significance of the characters '& > * + *' in JSX (CSS)?

When using material UI, the progressbar demo includes lines of JSX code like this: '& > * + *': { marginTop: theme.spacing(2), }, Can you explain what the selector '& > * + *' represents in this context? ...

necessitated in specified input with assigned value

Here is some code I have: <!DOCTYPE html> <html> <body> <form action="/action_page.php"> <select required> <option value=1>Volvo</option> <option value=2>Saab</option> <option value=3>Merc ...

Display all attribute connections for a product in Prestashop

I have updated the products in my shop to include different combinations. These combinations involve a 'packaging' attribute with two options: a 100 units box and a 200 units box, each with its own unique reference number. On the product page, t ...

Perform the action when the button is clicked

I'm struggling with finding a solution to this problem. I have an input field and a submit button. My goal is to update the value of a variable to match the value in the input field when the submit button is clicked. Additionally, I need to execute a ...

What is the best way to toggle and slide two forms within a single page?

In this scenario, the goal is to display multiple forms on a single page, like a Login Form and Reset Password Form shown below. One form is initially hidden until a link is clicked, triggering an effect. The current setup includes a .toggle() effect that ...

Employing ngModel in an option dropdown

I am having trouble passing an attribute from an API call to a submit function. I suspect it might have something to do with either the option select or how the input is being formatted. Encountering the error Error: No value accessor for form control wit ...

The bottom section is impacted by the bootstrap class

Currently, I am in the process of designing the store page for my website and have encountered an issue. I implemented a search function for the site, which works well. However, on the search.php page where the items are displayed based on the search query ...

Positioning a span to be below an input field

Below is the code for a Blazor component that includes a textbox which can be edited with the click of a button. @if (_editing) { <div class="floatingbox position-relative"> ...

Utilizing ng-click within ng-repeat along with $index

I'm experimenting with using ng-click on a div that is part of an ng-repeat loop, utilizing $index as seen in the code below : HTML: <div class="elementContainer" ng-repeat="element in elements" ng-click="elementUrl($index)"> <h2>{{ ...

The high chart data is failing to load

I am brand new to highchart and have just started learning how to create a simple pie chart in HTML. Unfortunately, I am having trouble getting it to work properly. Everything seems correct to me, but for some reason, the highchart is not populating. Here ...

What seems to be the issue with my JQUERY and CSS implementation?

I'm looking to create a click function that toggles the 'text decoration' setting to 'strike-through'. Additionally, I would appreciate any guidance on how to make it move to the bottom of the list when clicked. $(".player-nam ...

When hovering over the menu, the underline appears, not based on the length of the

Is there a way to make the underline below menu items on hover match the length of the word instead of the element? <nav class="navbar navbar-expand-lg navbar-light"> <a class="navbar-brand active" href="index.html"> <img src= ...

Create static HTML web pages using information from a text file

Exploring a new concept of a random joke generator that loads a unique html page with a quirky joke every time. Currently, the main index page is structured like this: <!DOCTYPE html> <html> <head><title>Jokes</title> ...

What is the best way to hide the background of an extension's HTML?

Currently, I am working on developing a Chrome extension for a university project. However, I am facing challenges in making the background or body of the extension's HTML completely transparent to achieve a cleaner interface. The issue specifically l ...

What is the best way to include an active CSS class in a menu item?

Link to example Can you figure out why the Home button is not turning red in this code snippet? .navbar a:hover, .navbar a:focus, .navbar a:active { color: red !important; } <nav class="navbar navbar-expand-lg"> <div class="collapse navbar ...