Achieve full width for container using flexbox styling

In an attempt to develop a category dropdown menu with multiple columns based on the length of the <ul>, I am facing some challenges.

For reference, you can view the fiddle that I have created here.

The goal is to arrange each submenu item below the previous one until it reaches the height limit, at which point a new column should be started. The desired layout is illustrated as follows:

Main category
 |
 subcategory1                         subcategory3
  |subsub1 for subcategory1            |subsub1 for subcategory3 
  |subsub2 for subcategory1           |
 |                                    subcategory4
 subcategory2                          | etc...
  |subsub1 for subcategory2 
  |subsub2 for subcategory2 
 --------------------------------------------------------------------  
 // total height of the dropdown 
    is reached here

I have utilized flex-flow and it seems to be functioning well. However, my issue lies in getting the dropdown container to expand full-width with a background color.

The HTML structure that I have used is:

<div class="cats">
      <ul>

        <li class="item sub">
          <a title="Baby" href="http://ministry.webshopapp.com/baby/" class="itemLink">Baby</a>
          <div class="subnav">
            <ul class="flex-wrap">
              <li class="subitem title"><a title="Borstvoeding" href="#" class="title">something</a></li>
              <li class="subitem"><a title="ATTITUDE" href="#" class="subitemLink">ATTITUDE</a></li>
              <li class="subitem"><a title="Apple Park" href="#" class="subitemLink">Apple Park</a></li>
              <li class="subitem title"><a title="Borstvoeding" href="#" class="title">something</a></li>
              <li class="subitem"><a title="ATTITUDE" href="#" class="subitemLink">ATTITUDE</a></li>
            </ul>
          </div>
        </li>
</ul>
</div>

The CSS styling applied is as follows:

.cats .subnav {
  background: #fff none repeat scroll 0 0;
  border: 1px solid #eee;
  padding: 30px;
  position: absolute;
  text-align: left;
  z-index: 99;
  display:none;
}
.cats .item.sub:hover .subnav {
  display: block;
}
.flex-wrap {
  background: #fff none repeat scroll 0 0;
  display: flex;
  flex-flow: column wrap;
  height: 200px;
}
.subnav .subitem {
  background: #fff none repeat scroll 0 0;
  line-height: 36px;
}

My question pertains to how I can configure .subnav to dynamically adjust its background size according to the content.

Answer №1

Below is the CSS code you need to implement:

Include left and right in your selector .cats .subnav

.cats .subnav {
    right: 0;
    left: 0; 
}

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

Encountering issues with integrating Sass into Angular 4

Hi there! I recently started a new project in Angular 4 and encountered some issues with the Sass styling. Every time I try to add sass and run the project, I keep getting this error message: body{ h1{ color : red; } } ^ Invalid ...

Filtering tables in Angular 6 using checkbox options

I have a functional code snippet that filters a table using checkboxes. However, I am facing an issue when unchecking a checkbox. It does not return the original array as expected. .html <ng-container *ngFor="let group of groups"> <label cla ...

Tips for hiding text on hover effect

I'm currently working on a menu where each item displays text that is replaced by an email address on hover. However, I am struggling to remove the text during the hover state. Below is the code I have written so far: #home { font: 30px 'Le ...

What steps should I take to create a slider using my image gallery?

I have a unique photo gallery setup that I'm struggling with: As I keep adding photos, the cards in my gallery get smaller and smaller! What I really want is to show only 4 photos at a time and hide the rest, creating a sliding effect. I attempted ad ...

The slider thumb is not showing up properly on Microsoft Edge

Hey there! I'm experiencing an issue with the range slider's thumb display in Microsoft Edge. It appears to be positioned inside the track rather than outside as intended. Take a look at this snapshot for clarification: https://i.stack.imgur.co ...

What are the steps to create a hovering dropdown menu that changes the background window to transparent when hovered over?

Is there a way to create a dropdown menu that changes the background window to transparent when hovered over? Here is an example of what I am looking for: https://i.sstatic.net/FplLm.png The dropdown menu should look like this when hovered over: https: ...

Cannot locate module: Error: Unable to find the path '../containers/Layout' in '/home/yusquen/Projectss/react-shop/src/components'

https://i.stack.imgur.com/U1097.png description of image goes here Issue with module: Error: The file '../containers/Login' could not be found in the 'react-shop/src/components' directory. ...

Guide to integrating various HTML files into a single HTML file with the help of Vue.js

Although I am familiar with using require_once() in PHP, unfortunately, I am unable to use PHP in my current project. I attempted to use w3-include from W3Schools as an alternative, but encountered issues with loading my scripts. Even utilizing JavaScript ...

Rotate the image using the handler, not by directly manipulating the image itself

I need help rotating the image using a handler instead of directly on the image itself. I do not want to rotate the image when clicking and rotating it directly. Please do not suggest using Jquery UI rotatable because resizing the image with Jquery UI resi ...

The complexities of stopPropagation() causing further confusion

I have encountered an issue with my code. It currently allows a dropdown functionality for a <ul> element, but when a child <li> is clicked, it also closes other menus of the same type. To fix this, I used an if clause to check if the clicked ...

What is causing the input boxes to exceed their container boundaries so drastically?

My plan was to organize 4 input text boxes in 4 equal columns on a single row of the form. Using Bootstrap's grid column classes, I set col--3 for medium and large screens for those four inputs. For small and extra-small sizes, I designated them as co ...

When attempting to implement sound on hover with an <a attribute containing an image>, the functionality is not functioning as expected

Is there a way to make a sound play only once when hovering over a list item that contains an image? Here is the HTML and JavaScript code I am using: function playclip() { var audio = document.getElementsByTagName("audio")[0]; audio.play(); } <ul ...

I prefer to not have the box-shadow showing up on top of the navigation bar

Check out this cool demo: View Demo I am looking to add a shadow effect above the footer section, but not above the navigation bar. nav{ background-color: blue; height: 100px; } main{ box-shadow: 0px 0px 16px 2px rgba(0, 0, 0, 0.5); background- ...

Having troubles with angular due to doodle throwing errors?

https://codepen.io/tuckermassad/pen/rPYNLq I took the CSS doodle code from the above link and incorporated it into my angular component: <section class="main"> <css-doodle grid="5"> :doodle { @grid: 10 / 100%; } ...

Display or conceal numerous WTForm labels

Is there a more efficient way to hide/show multiple wtform labels? Currently, I am achieving this with the following code: HTML: {{ render_field(var_1, class = "class_1") }} {{ render_field(var_2, class = "class_1") }} {{ render_field(var_3, class = " ...

"Combining HTML, PHP, and JavaScript for Dynamic Web

Here is the PHP function that retrieves the visitor's profile image thumbnail: <?php echo voip_profile_image($visitorid,'thumb'); ?> The issue lies in the fact that $visitorid is stored in JavaScript under the sRemoteid parameter. Wi ...

Sort the data - a selection menu is included in each row of the table

My issue involves a datatable where each row must have a select item with multiple options to choose from. The goal is to filter the rows based on the selected option when using the default search bar located above the table. However, I've encountered ...

Navigate to a precise section of the webpage, positioned at a specific distance from the top

When scrolling on my page, the static header moves along with the user. However, when I link to a specific div using the standard method, the div appears behind the header. I would like to utilize: <a href="#css-tutorials">Cascading Style Sheet Tut ...

Preventing button movement during navigation collapse toggle click

I am working on setting up my navbar in the following way: [collapse] navbar icon links sign in button Although I have successfully set this up, the issue is that when the navbar collapse toggle is clicked, it shifts the sign-in button u ...

Using JavaScript to manipulate HTML content that has been dynamically injected using AJAX

I am in the process of developing a portfolio website where I want to fetch partial HTML files using an AJAX request. Here is the basic structure of the HTML: <div id="portfolio"> // Content will be replaced here </div> <a ...