Adjust the width of the list items based on the specified condition

I need assistance with adjusting the width of items in a list. The list includes:

<ul>
    <li>One</li>
    <li>One-One</li>
    <li>Two</li>
    <li>Two-Two</li>
</ul>

The display should be dynamic, switching between two columns and one column. For example:

Two Column Scenario

One | One-One

Two | Two-Two

One Column Scenario

One

Two

I am using AngularJS with HTML5 and CSS3. Any guidance on how to adjust the width according to the scenario would be greatly appreciated.

Thank you for your help in advance.

Answer №1

Here is a solution that utilizes the display:flex property and @media queries. See the example below, and try resizing the output window to see it in action.

ul {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}
li {
  width: 50%;
}
@media (max-width: 40em) {
  li {
    width: 100%;
  }
  li:nth-child(even) {
    display: none;
  }
}
<ul>
  <li>One</li>
  <li>One-One</li>
  <li>Two</li>
  <li>Two-Two</li>
</ul>

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

Is it possible to open a new tab window using a radio button?

Looking for assistance with radio buttons. I want users to be redirected to a new window when they click the submit button beneath the radio buttons. If anyone has a solution, please help! I have tried using window.location.href and window.open but the c ...

I'm curious about the method used to create this body fadeIn effect

Recently, I stumbled upon the website "". I must say, it is truly remarkable. I can't help but wonder how the content on this page is cleverly faded in and slides up. This specific page caught my attention: ...

"Enhancing the aesthetics: Stylish blue borders around Bootstrap

After successfully setting up bootstrap-select, I have noticed that blue borders are showing in two specific instances: 1) within the dropdown menu 2) when a new value is selected I have made some adjustments but the issue persists. Can someone please p ...

Disappearance of CSS borders when using jQuery scroll function

After implementing a fixed table header for an HTML table on my website, I encountered a minor issue. When scrolling down, the table header remains at the top as intended, but the CSS styling for borders within each <th> element disappears. The font ...

Creating a design where the divs on the sides utilize all the available space using only CSS and HTML

I am trying to create a layout with three <div> elements - one centered at 960px width, and the other two on each side. My goal is to have the side divs take up all available space except for the 960px occupied by the centered div. I managed to achi ...

JavaScript and HTTP Post parameters: Consider using optional additional parameters

Managing a filtration function, I have an array of checkboxes and dropdowns. Users can select multiple checkboxes and dropdown values before clicking on the "Filter Now" button. Upon clicking the button, a POST request is triggered to my API, passing alon ...

Modify a website link using Javascript by detecting two separate button clicks

I am seeking a way to dynamically change the src attribute of different images on a house depending on which button has been clicked. There are two groups of buttons: The types of house parts, such as windows, doors, garage, soffits, and gutters. The col ...

Is there a way to use flexbox in a grid to center only a specific tab from MUI?

I am working with an array of tabs and encountering a layout issue. The tabs need to share the available space when there's more than one tab, but when there's only one tab, it should be positioned in the middle of the column. How can I address t ...

Displaying varied information based on JSON feedback using AngularJS

I am currently in the process of developing an app using AngularJS and the Ionic framework. The app will display a list of data with various subcategories for each item, depending on the account type. View sample image here The issue I am facing is that ...

Assigning a unique identifier to a button that will vary depending on the selected radio input

UPDATED HTML: The circumstances have changed because I am no longer in my office, but the concept remains unchanged. The situation is that on a certain part of a website, users have the option to choose from multiple saved addresses. Each address has a un ...

Preventing users from clicking on links unless they double click by using CSS rotation

I'm struggling to figure out why only the white portion of my links is clickable. The links are designed as "3D" buttons using CSS rotate transitions, but I can't seem to fix the issue. Any assistance would be greatly appreciated! Check out the ...

Tips for maintaining the cleanliness of PHP-generated HTML output in the 'View Source' option

I've been noticing a problem today while examining the source code on a website. I typically use PHP output in my templates to generate dynamic content. Initially, the templates are written in HTML only, with clean indentation and formatting. The PHP ...

Tips for managing variations in the naming conventions of JSON fields in request bodies when transferring data from JavaScript to Python using Django REST framework (DRF)

As I work on creating Rest APIs in Python DRF and consuming them in angularJS, I am encountering a challenge related to the naming conventions of variables in JavaScript and Python. JavaScript typically uses camel case for variable names, while Python fol ...

Rotating Cursor during AJAX loading process

I utilize a WebGrid across many of my pages to showcase various products. Within the code snippet below, you can see how an item is added to the database when a user clicks on it: public bool ToCart(int userId, string partNumber, ...

What could be the reason my Angular interceptor isn't minified correctly?

I have come across this interceptor in my Angular project: angular.module('dwExceptionHandler', []) .factory('ExceptionInterceptor', ['$q', function ($q) { return function (promise) { return promise.th ...

Trouble with post synchronization in Angular-Fullstack app following update

Within my Angular-fullstack application, I am able to successfully post content on my post overview page. However, I have encountered an issue with my socket update when trying to post a comment on a single post page. Here is my schema: var PostSchema = ...

Several pictures are not displaying in the viewpage

I have a controller method set up to fetch files from a specific folder. public JsonResult filesinfolder(ProductEdit model) { string productid = "01"; string salesFTPPath = "C:/Users/user/Documents/Visual Studio 2015/Projects/root ...

React snap scrolling feature is not working as intended

I've been attempting to implement the snap scroll feature in my react app, but I'm facing issues with it. The regular CSS method doesn't seem to work well in Chrome, as discussed in this Scroll Snap Skips Section on Smaller Screen - Chrome t ...

What is the best way to capture ng-keypress/ $event when the user clicks outside of a div?

I am currently working on developing a Sudoku game using AngularJS. My goal is to capture the ng-keypress event even when clicking outside of the div on the page. An example of this behavior can be seen at . If you select a cell and then click anywhere els ...

When an HTML input button within a table fails to trigger any jQuery function upon being clicked

I currently have a table set up with multiple rows and columns. <table style="width: 100%;" class='table_result'> <tr><td>Text</td><td>Text</td><td>Text</td><td>Text</td> ...