What is the best way to conceal the li elements that exceed a single line?

I have a unordered list containing product information as list items. My goal is to hide the list items that do not fit on a single line based on the screen size.

Therefore, the number of products displayed should adjust depending on how many can fit on a single line, which in turn relies on the user's screen size.

Here is how I envision it:

This is the current appearance:

How can I achieve this? Can it be done using just HTML/CSS or will I need to incorporate JS/JQuery?

JSFiddel:

http://jsfiddle.net/narzero/5v3jL4wx/

HTML:

<body>
  <div class="content_panel active">
    <ul class="unstyled items_board">

      <!-- VEGETABLES - FRUITS - POTATOES -->
      <li class="item_header">VEGETABLES - FRUITS - POTATOES</li>
      <!-- One -->
      <li class="item ">
        <div class="media">
          <img src="http://goo.gl/6KJFwk" alt="One">
          <div class="info_group">
            <span class="price_info"><button class="btn btn_price">€2.03</button></span>
            <span class="add_button"><button class="btn btn_success">Add</button></span>
          </div>
        </div>
        <div class="item_info">
          <div class="item_name item_row">
            <span class="full_item_name">Aarts Frambozen op siroop</span>
            <span class="item_size muted">370 ml</span>
          </div>
        </div>
      </li>
      <!-- Two -->
      <li class="item ">
        <div class="media">
          <img src="http://goo.gl/A4IzmQ" alt="Two">
          <div class="info_group">
            <span class="price_info"><button class="btn btn_price">€2.63</button></span>
            <span class="add_button"><button class="btn btn_success">Add</button></span>
          </div>
        </div>
        <div class="item_info">
          <div class="item_name item_row">
            <span class="full_item_name">AH Aardappelen iets kruimig</span>
            <span class="item_size muted">3 kg</span>
          </div>
        </div>
      </li>
      [...]
    </ul>
  </div>

CSS:

body {
  background: #fcfcfc;
  font-family: "Open Sans", "Helvetica Neue", Helvetica, sans-serif;
}

/*==== Content panel ====*/
.content_panel .active {
  display: inherit;
}
[...]    

Answer №1

If you have a list that can be split into two separate <ul> ... </ul> elements for different categories, you can apply the CSS property overflow: hidden;

ul {
    height: 300px;
    width: 100%;
    overflow: hidden;
}

Check out the working example on fiddle: http://jsfiddle.net/5v3jL4wx/1/

Answer №2

I made some adjustments to the CSS and included a ul tag to end the first one.

After making those changes, here is the updated result:

Check out the updated FIDDLE

 .unstyled {
    font-size: 0;
    margin-left: 0;
    list-style: none;
    outline: 1px solid red;
    white-space: nowrap;
    overflow-x: scroll;
}

You may notice that I added overflow-x: scroll; to enable left or right scrolling to view the entire content. Additionally, I included white-space: nowrap; to keep the text in a single row.

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

What is the best way to organize large amounts of data into an array?

I am currently working on developing a unique version of wordle using javascript and html. In order to do this, I require a comprehensive list of all possible wordle words stored in an array format. Although I have the words listed within a document contai ...

How to conditionally set the active class in a React component

I am new to using React and I am encountering some issues. My goal is to add an active class when any of these components are opened. I have attempted a solution but it isn't working as expected. I need assistance in adding a background color to the d ...

Problems encountered with operating the Bootstrap burger menu

After following the Bootstrap navbar documentation and implementing the code in my bs-navbar.component.html file, I encountered an issue with the hamburger menu. Despite everything being set up correctly, clicking on the hamburger icon did not display the ...

Executing a Shortcode Using a Button in Visual Composer for Wordpress

It should be easy to do this. I've got a great plugin with a modal newsletter signup form that offers various launch options, including manual launching with the following codes. https://i.stack.imgur.com/IGbsp.png My theme utilizes Visual Composer. ...

Easily implement a wide variety of fonts in your web projects by dynamically loading hundreds of font

I am in possession of a directory called /assets/fonts containing a plethora of fonts that I wish to incorporate into a website in a dynamic manner. Users will be able to specify their font preferences, akin to a text editor. Individually assigning the fo ...

Slider MIA - Where Did it Go?

I'm having an issue with my slider. When I load the page, it doesn't show the first image until I click the button to load it. How can I make it display the first image by default? Below is my JavaScript code: <script> var slideIndex = 1 ...

Styling a disabled button in ASP.NET using CSS

I've encountered an issue with my asp.net button that is disabled based on specific c# code conditions. The button, known as btnPrevious, is assigned the css class below: .btnBlue{ background: rgb(40, 108, 244); /* Old browsers */ background:linear-g ...

Creating an HTML file with a Windows-inspired icon and file name design using CSS

I searched everywhere on the internet but couldn't find a solution. If anyone knows of a similar link to my question, please share it with me. I am trying to achieve a design similar to Windows icons and file names in HTML using CSS. Please refer to ...

Footer displays within the content section

Currently, I am utilizing Next.js and antd's layout components to create a dashboard-style page using their Layout component. However, I have encountered two issues related to styling (CSS) in this setup: Footer appearing within the Content: I am wo ...

Solution for Organizing Tables

I've sourced data from various JSON API links and displayed it in a table. Currently, my code looks like this: <script src="js/1.js"></script> <script src="js/2.js"></script> Above this code is the table structure with <t ...

"Exploring the Dynamic Display of Ajax with HTML5 Canvas

This is my first time exploring the world of ajax, and I'm finding it quite challenging to grasp the concept and functionality. What I aim to achieve: I envision a scenario where I can freely draw on a canvas and simply hit save. Upon saving, the da ...

Is there a way to make a Bootstrap grid with four columns span across two rows in the second column?

How can I create a Bootstrap grid with four columns where the second column spans two rows? Hello, I am looking for help to achieve a portfolio grid layout with 4 columns (refer image here) and have the second column span 2 rows. I plan to include images ...

When I try to call jQuery's getScript function, the callback does not execute as expected within

When I invoke the script in a function at runtime function CheckOutMyFace() { $.getScript("/scripts/jtimers.js", function (data) { }); }; I notice in Firebug that the script is being called every time the function is invoked, but for some reason the ...

Utilize a single JavaScript file to handle various views without encountering errors due to undefined functions

My backend editing requires a single JS file. However, I face the challenge of needing different sets of methods for view A and view B — never both at the same time. To streamline this process, I combined all the jQuery functions for both views into one ...

Iterate over JSON data and display the outcomes

I need assistance with extracting and printing error messages from the provided JSON using jQuery. Any guidance would be greatly appreciated. Thank you! var validationErrors = {"errors":["Please enter the month (1-12)","Please enter a day 1-31"]} Edit, ...

Duplicate the PHP code for every section found within an INI file

<? $config = parse_ini_file('/list.ini', true); ?> <?echo'<select id="LBox" name="listbox" size="20" style="display:none;">'; foreach($config[MPR] as $id=>$label){ switch ($id) { case ($id== ...

What is the best way to bring my image to life and move it to

Just starting out with HTML and CSS. Can anyone help me learn how to animate my image so that it moves from its current position to another location? For example, transitioning from "top: 280px; left: 600px;" to "top: 180px; left: 500px;" I'm looking ...

Is it possible to customize the color of the placeholder and clear-icon in the ion-search bar without affecting

I am working with two ion-search bars and I need to customize the placeholder and clear icon color for just one of them. <ion-searchbar class="search-bar" placeholder="search"></ion-searchbar> My goal is to target a specific i ...

Adding a div with a canvas element is malfunctioning

I've been experimenting with using canvg to convert an SVG within a div into a canvas. So far, the conversion is working fine but when I try to copy the innerHTML of the div to another div, it's not functioning properly. The canvas is being gener ...

Insert a constant array using Jquery into another array

Hello, I am facing a dilemma where I have an empty array in one file and another array with data in a different file. My goal is to transfer all the data from one array to the other, but there's a complication - the array is stored within a CONSTANT. ...