Styling the alignment of category menu columns using CSS

I'm looking for advice on customizing a menu in Magento. The current menu is functional, but I'm not happy with how the items are aligned on the website. Below, you'll find an image of the current menu and another one displaying my preferred layout.

Current Menu: https://i.sstatic.net/qrcGN.jpg

Preferred Layout (from a different site, but captures the right feel): https://i.sstatic.net/yLFQ5.jpg

The website in question is autoshopdirect.nl. I'm just looking for some initial guidance to help me get started. It involves an unordered list (ul) with list items (li), each styled using the following CSS:

   .nav-primary .child-container li.level1 {
        float: left;
        display: block;
        width: 190px;
        min-height: 138px;
        margin: 10px;
        line-height: 1.5em;
    }

Answer №1

To achieve the desired layout, you can utilize CSS columns.

Add column-count: 4; to the container of your items to set the number of columns.

If you want to prevent an item from breaking into a new column, include column-break-inside: avoid; in your item's styling. Otherwise, you can skip this part of the code if column breaks are acceptable.

This is a sample layout without using column-break-inside: avoid;:


Menu Header   menu-item     menu-item     Menu Header 
menu-item     menu-item     menu-item     menu-item
menu-item                   menu-item     menu-item
menu-item     Menu Header   menu-item     menu-item
menu-item     menu-item     menu-item     menu-item

ul {
  margin: 0;
  padding: 0;
  list-style: none;
}
#content > .group {
  margin: 0;
  padding: 10px;
  border: 1px solid #cfcfcf;
  background-color: #ddd;
  -webkit-column-count: 4; //Defines the number of columns you want
  -moz-column-count: 4;
  column-count: 4;
}
#content > .group .item:first-child {
  margin-top: 0px;
}
#content > .group .item {
  padding: 10px;
  display: list-element;
  -webkit-column-break-inside: avoid;
  -moz-column-break-inside: avoid;
  -o-column-break-inside: avoid;
  -ms-column-break-inside: avoid;
  column-break-inside: avoid;
}
<div id="content">
  <ul class="group">
    <li class="item"><strong>Item</strong>
      <br/>Subitem
    </li>
    <li class="item"><strong>Item</strong>
    </li>
    <li class="item"><strong>Item</strong>
      <ul>
        <li>Subitem</li>
        <li>Subitem</li>
        <li>Subitem</li>
      </ul>
    </li>
    <li class="item"><strong>Item</strong>
    </li>
    <li class="item"><strong>Item</strong>
    </li>
    <li class="item"><strong>Item</strong>
      <ul>
        <li>Subitem</li>
        <li>Subitem</li>
        <li>Subitem</li>
      </ul>
      <li class="item"><strong>Item</strong>
      </li>
      <li class="item"><strong>Item</strong>
      </li>
      <li class="item"><strong>Item</strong>
      </li>
      <li class="item"><strong>Item</strong>
      </li>
      <li class="item"><strong>Item</strong>
      </li>
      <li class="item"><strong>Item</strong>
      </li>
      <li class="item"><strong>Item</strong>
      </li>
      <li class="item"><strong>Item</strong>
      </li>
  </ul>

</div>

Answer №2

New for 2021: Ensure to implement the following guidelines on all elements within the specified list

-webkit-column-break-inside: avoid; /* Supported by Chrome, Safari, Opera */
          page-break-inside: avoid; /* Compatible with Firefox */
               break-inside: avoid; /* Working in IE 10+ */

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 measures can be taken to prevent content from collapsing?

My goal is to create a navigation system using Bootstrap 4's collapse feature to display content based on buttons at the top of the page. Here is my navigation bar setup: <div class="port-item p-4 bg-primary" data-toggle="collapse" data-target="# ...

The phenomenon of bootstrap tooltips resizing the screen upon hover activation

Trying to incorporate a tooltip on an element of my website, I have "data-toggle="tooltip" data-html="true" title="This is my tooltip text" The issue arises when I hover over the element, as the tooltip first flashes at the bottom of the page. This cause ...

Item template with dynamic content for pagination directive

My current implementation includes a paginator directive that displays items from an array: .directive('paginator', function() { restrict: 'A', template: '<div ng-repeat="item in items">' ...

Round up all the hyperlinks within a paragraph and organize them neatly into a list

Let me present a scenario: <p class="links">Lorem <a href="#">diam</a> nonummy nibh <a href="#">Lorem</a></p> Following that, I have a lineup: <ul class="list"> </ul> How do I achieve this using jQuery? ...

The .htaccess directive aimed at eliminating .html from the URL appears to be malfunctioning

Struggling to remove the .html extension from your page URLs? I've been trying various methods with the .htaccess file, but nothing seems to be working. I created an .htaccess file and placed it in the public_html directory. The code snippet I'm ...

How to Style Django's Multiwidget & MutliValueField Textarea with Crispy Forms

I've created a custom form field setup using a TextField to store a large amount of text split into 10 logical parts. To achieve this, I decided to create 10 individual Textarea fields by subclassing both MultiWidget and MultiValueField: class MultiWi ...

`html2canvas encountered an issue: Unable to locate a logger instance`

When I use html2canvas to render the same content repeatedly, I encounter an error about 5% of the time. It seems to be sporadic and I'm not sure why it occurs. What could be causing this unpredictable behavior? html2canvas.js:2396 Uncaught (in promi ...

Tips for managing three select menus in AngularJS

Assistance needed for creating a series of interconnected dropdown menus in AngularJS. The functionality should allow the second dropdown to open upon selecting a value in the first dropdown, and the third dropdown to open upon selecting a value in the sec ...

The HTML Canvas arc function fails to properly align curves

UPDATE Upon further investigation, I've discovered that this problem only occurs in Chrome. Could it be a browser issue rather than a coding problem? I'm working on creating a circle with clickable sections using HTML5 Canvas. The circle itself ...

Retrieve data from an HTML form and utilize it to search a JSON array for a specific value

If I have a Json File structured like this: {"403": [ { "403-01-01": "219,00" }, { "403-01-02": "180,00" } ], "404": [ { "404-01-01": "26,00" }, {"403-01-02": " ...

Flask does not display images in CSS files

Starting with the frontend (HTML, CSS) of my project, I then proceeded to create a Flask file with the following code: from flask import Flask, render_template app = Flask(__name__) @app.route("/", methods=["GET"]) def index(): return render_templa ...

arrangement of a list with the specified information stored in each item

Presently, my task involves setting up a dynamic gallery page with multiple tabbed lists that are fetched from the database. Each list corresponds to a specific Gallery Name and is associated with a unique data-list-id. Furthermore, each gallery contains ...

Using CSS to remove the background of a dropdown button in a <select> element

I need to style a <select> element so that it appears like plain text until clicked, revealing the pulldown choices. Ideally, I would like to include small arrows to indicate multiple options, but I can add those as image overlays if necessary. My p ...

Attempting to place words beneath an image can distort the overall layout

Having trouble aligning text under 3 images in a row? All the solutions I've come across end up stacking the images vertically instead of horizontally. HTML: <div id="SecondFooter" class="responsiveColumn"> <a href="link here" t ...

Issues arising with transferring information between components

My webpage had a header with a search engine input, a list of posts, and pagination all on one page. I made the decision to separate the header into its own component in a different Vue file. However, after making this change, searching for posts by their ...

Display the chosen date from the datepicker in the input field

Utilizing a JQuery DatePicker to be constantly displayed, I have assigned it to a div. Despite wanting it to display the selected date in the input box like in this example, it just isn't functioning as desired for me. Is there a way to have the selec ...

"Unsuccessful API request leads to empty ngFor loop due to ngIf condition not being

I have been struggling to display the fetched data in my Angular 6 project. I have tried using ngIf and ngFor but nothing seems to work. My goal is to show data from movies on the HTML page, but for some reason, the data appears to be empty. Despite tryin ...

Adjust the flexslider to transition to a new slide when hovering over the thumbnails

I have a flexslider with thumbnails like this ; https://i.stack.imgur.com/9bfC2.jpg I am looking to change the slide when the user hovers over the thumbnails. How can I achieve this functionality? Here is the jQuery code I am currently using to set up th ...

Tips for retrieving the count from HTML using JavaScript:

I need to determine the count of list items in an unordered list within dir-pagination-controls. How can I achieve this using JavaScript? <dir-pagination-controls min-size="1" direction-links="true" boundary-links="true" class="pull-right ng-isolate- ...

Managing the vertical space within a nested accordion section

I've built a custom accordion component, but I'm encountering scrolling issues when trying to use nested levels within the accordion. I'd like to prevent scrolling inside the accordion section and instead have the page scroll below it. Any ...