Adjust the size of an image based on the size of the screen

I am currently working on creating a navigation menu using icons that need to resize as the screen size changes. Here is my progress so far:

http://jsbin.com/yesitepuwo/edit?html,css,output [it's possible that the link does not work in firefox?]

Currently, when resizing the window, the images collapse and stack on top of each other before resizing properly. I would like them to only resize without collapsing. How can I achieve this?

If necessary, I am open to changing the HTML markup. However, at the smallest breakpoint, I would like to display a burger menu instead of the stacked icons. Is it possible to set a min-width for the images to prevent collapsing at this point?

Any help or suggestions would be greatly appreciated. Thank you! :)

Answer №1

Here is how you can style your list items:

ul{
  padding: 0px;
  border: 1px solid red;
}
ul:after {content:'';display:block;clear:both;}
li{
  display:block;
  float:left;
  max-width: 50%;
}
img {
  width:100%;
}
@media (max-width:300px) {
  li {max-width:100%;}
}

If you prefer inline-block elements, use the following code:

ul{
  padding: 0px;
  border: 1px solid red;
}
li{
  display:inline-block;
  max-width: 50%;
}
img {
  width:100%;
}
@media (max-width:300px) {
  li {max-width:100%;}
}

However, be sure to remove spaces between your li elements in order to avoid extra spacing due to inline-block elements being treated as words by the browser.

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

HTML containers continue to show gaps even with no margin or padding applied

I have a basic setup here with a single line of red text on a colored background. Despite setting margin and padding to zero and not having any child elements causing spacing issues, I still see a gap around my container. Here's my CSS: { width: ...

How can I modify the color scheme of radio buttons to include a variety of different hues?

Is there a way to customize the colors of my radio buttons with three different options? I want numbers 1, 2, and 3 to be red, number 4 to be orange, and number 5 to be green... Here is the code I am using: /* Option 1 */ input[type='radio'] { ...

AngularJS push not reflecting changes in one div but working correctly in another unspecified div

I'm encountering an issue where adding a new contact is updating the ul-li list, but not the select-option list. Here is the code snippet: <!DOCTYPE html> <html ng-app> <head> <title>Hello World, AngularJS - ViralPatel.net< ...

Iphone not picking up media queries, while browser resize is working perfectly

Hey there, I'm currently using a theme called Bones on my WordPress site, but I'm encountering some difficulties with the responsive menu on my iPhone. Oddly enough, when I manually resize the window, the menu seems to work just fine. Here' ...

Is there a way to expand "row" elements to the left side in Bootstrap?

<div class="container-fluid"> <div class="row"> <!-- Left side --> <div class="col-xl-10 style"> <div class="row" > <div class="col-xl-12 style">Box1< ...

Add hyphens to separate the words in AngularJS if there is a break in the string

Within a div of set width, a string is being bound to it. This string could be short or long. I would like for the string to break with a hyphen inserted on each line except for the last one. For example: If the string is "misconception" and it breaks at ...

Ways to align elements vertically in a container without using flexbox?

I am working with a ul element that has a height of 270px and contains 10 li elements. My goal is to have all the li elements vertically justified, meaning the top and bottom li elements should touch the container's top and bottom respectively, while ...

Position a div container to be aligned at the bottom of an image

I'm having trouble aligning a div container at the bottom of an image. I attempted to modify the position attribute of the image and set its value to "relative." It's a bit challenging to explain, but here are snippets of HTML and CSS code with ...

Determine the total quantity of colored cells within a row of an HTML table and display the count in its own

I need assistance with a table that has 32 columns. From columns 1 to 31, I am able to fill in colors by clicking on the cells. However, I now want to calculate and display the number of cells that are not colored in the last column. This task must be co ...

aligning content that has exceeded the boundaries

I have a list of dynamically created <a> tags without text, to which I apply background images. These icons are displayed within a <div> container using the float: left; style. As the row of icons becomes too long, it overflows and starts a ne ...

Struggling with making Custom CSS take precedence over Bootstrap in a Wordpress Theme

I'm facing an issue with my custom CSS not being able to override bootstrap on this specific site. Although I have experience using bootstrap on various platforms without any issues, I am currently working on a WordPress project for a client where no ...

Is it possible to apply CSS styling to all placeholders in a Sencha Touch application?

Having trouble figuring out how to style all the placeholders in my application with CSS. I've attempted a few different methods: .customField input::-webkit-input-placeholder { color: #2e4bc5; } .x-text-field input::webkit-input-placeholder{ c ...

Modifying button appearance based on state change in AngularJS

I have a button with a grey color and I want to create two different states for it: one that is selected (blue) and another that is in an idle state (grey). Currently, I am working on Angularjs but I am fairly new to this platform. Could you kindly provid ...

Modifying the Color of Individual Items within the Pagination Component in MUI

I am attempting to modify the background color of every item in my Pagination component by utilizing makeStyles. import { Pagination } from "@material-ui/lab"; import { makeStyles } from "@material-ui/core"; const pagination = makeStyl ...

Is it possible to integrate Bootstrap with RCloud?

While Shiny is fantastic, I have a strong desire to create my own responsive dashboard with custom branding. Is it possible to utilize Bootstrap within RCloud? ...

What is the best way to utilize *ngFor for looping in Angular 6 in order to display three images simultaneously?

I have successfully added 3 images on a single slide. How can I implement *ngFor to dynamically load data? <carousel> <slide> <img src="../../assets/wts1.png" alt="first slide" style="display: inline-blo ...

Angular 10 encountering issues with loading Bootstrap styles

I'm currently working on a project that involves Angular 10 and the Bootstrap library. However, I'm encountering an issue where the Bootstrap styles are not loading properly. Upon checking the package.json file, I can see that Bootstrap is liste ...

React - The mechanics behind a spinning roulette wheel

I've been attempting to create a React roulette spinner but I've encountered some issues with the transitions and functionality. Here is the initial version of the algorithm: The callback functions are triggered whenever the 'winner&apo ...

Tips for aligning text to the left instead of the right when it exceeds container width in IE 11

Within the div, there is text with a 5px margin on the right. When the container div narrows, the text overflows from the container and loses the right margin. Is it feasible to maintain this margin on the right side while allowing the text to overflow fro ...

Expand the image to fill the entirety of the viewing area

Check out my development website. Whenever you click on an image, a photo slider (using photoswipe) pops up. Is there any way to have the image fill the entire viewport? I attempted using height: 100vh, width: auto, but it didn't work. https://i.ssta ...