Using CSS flex with a column layout that does not expand to the full width of its parent

My vertical navigation bar includes the following list items:

<ul class="nav">
    <li>
      <div>
        <i class="fa fa-tachometer"></i>
        <a href="#" class="noselect">Dashboard</a>
      </div>
    </li>
    <li>
      <div class="act_item">
        <i class="fa fa-users"></i>
        <a class="noselect">Groups</a>
        <span class="arrow_right"></span>
      </div>
    </li>
    <li>
      <div>
        <i class="fa fa-archive"></i>
        <a class="noselect">Projects</a>
        <span class="arrow_right"></span>
      </div>
    </li>
    <li>
      <div>
        <i class="fa fa-cogs"></i>
        <a class="noselect">Settings</a>
      </div>
    </li>
  </ul>

CSS:

  .left .nav {
margin-top: 1em;
display: flex;
display: -webkit-flex;
flex-direction: column;
-webkit-flex-direction: column;
position: relative; }
.left .nav li {
  position: relative;
  cursor: pointer;
  background: #1879C7;
  display: flex;
  display: -webkit-flex;
  flex-direction: column;
  -webkit-flex-direction: column;
  align-items: flex-start;
  box-sizing: border-box;
  border-top: 2px solid #4D5A63; }
  .left .nav li:last-child {
    border-bottom: 2px solid #303E47; }
  .left .nav li:hover > div {
    margin-left: 0.5em; }
  .left .nav li div {
    position: relative;
    -moz-transition: all linear 0.2s;
    -o-transition: all linear 0.2s;
    -webkit-transition: all linear 0.2s;
    transition: all linear 0.2s;
    display: flex;
    display: -webkit-flex;
    flex-direction: row;
    -webkit-flex-direction: row;
    height: 30px;
    padding: 0.5em;
    background: #243139; }
    .left .nav li div i {
      position: relative;
      padding-top: 5px; }
    .left .nav li div a {
      position: inherit;
      margin: auto 1em auto 0.5em;
      font-size: 18px;
      color: #F4F4F4; }
    .left .nav li div .arrow_right {
      margin: auto 0 auto auto; }
  .left .nav li .act_item {
    margin-left: 0.5em; }

https://i.sstatic.net/60kaA.png

I am looking to extend the options under "Groups" in my navigation, but when I set .nav > li with flex-direction: column, the child div does not expand to fill the parent li.

I have attempted to use width:100% on the child div, but this causes overflow and hides the arrow.

Is there a way to make the child div (inside .nav > li) expand to fill the parent element while maintaining flex-direction:column; for the list?

Answer №1

Is this what you are looking for? To achieve the desired effect, set the width to 100%; and apply box-sizing: border-box; to prevent content from breaking out of the box.

Instead of using margin-left on the active item, I applied border-left: 10px solid #1879C7 as margins can interfere with box-sizing:border-box;.

For more information on the box-sizing property, visit Mozilla Developer Network. Check out my demo below.

 .left .nav {
    margin-top: 1em;
    display: flex;
    display: -webkit-flex;
    flex-direction: column;
    -webkit-flex-direction: column;
    position: relative;
  }
  
  ...
  
  .left .nav li .act_item {
    border-left: 10px solid #1879C7;
  }
<div class="left">


  <ul class="nav">
    <li>
      <div>
        <i class="fa fa-tachometer"></i>
        <a href="#" class="noselect">Dashboard</a>
      </div>
    </li>
    <li>
      <div class="act_item">
        <i class="fa fa-users"></i>
        <a class="noselect">Groups</a>
        <span class="arrow_right"></span>
      </div>
    </li>
    <li>
      <div>
        <i class="fa fa-archive"></i>
        <a class="noselect">Projects</a>
        <span class="arrow_right"></span>
      </div>
    </li>
    <li>
      <div>
        <i class="fa fa-cogs"></i>
        <a class="noselect">Settings</a>
      </div>
    </li>
  </ul>

</div>

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

Tips for preventing background scrolling of a Fixed element in React

Currently, I am working on a project using NextJS with Tailwind CSS. I am in the process of creating a drawer, popup, and modal with the CSS property position: fixed. However, I have encountered an issue where when I scroll on the fixed elements, the bac ...

Tips for achieving the perfect spacing between inline-block elements

A sample scenario: https://i.sstatic.net/gmyS0.png Is it feasible to maintain consistent spacing between inline div elements? The challenge lies in the fact that auto width does not seem to be effective in achieving this. Here is the progress I have made ...

Having issues integrating Soundcloud iframe into Bootstrap 4

Explore the website First and foremost, I want to express my gratitude to all those who are willing to assist me! As a complete beginner, I hope my explanation will be clear enough. I am in the process of constructing a music label website using Bootstrap ...

Implementing a JQuery script that triggers every time there is a change in the scroll

This script creates a shrinking effect on a box followed by a fade-in/out transition when the scroll position changes. However, the issue is that it triggers every time there is a scroll position change. For example, if the scroll position is at 100px and ...

Creating a sequence of isometric foes in the right arrangement or tackling the task of handling the stained rectangle?

Can someone lend a hand in fixing my Z-index order? I've been staring at this code for hours and my eyes are starting to cross. Maybe leaving a question on Stack Overflow overnight will steer me in the right direction. I've been tinkering with h ...

The Django static files were uncooperative and refused to function

I've encountered an issue with my HTML files while using Django. Some files work perfectly fine when I load static files, but others don't seem to cooperate. I'm perplexed as to why this inconsistency exists! Have I overlooked something impo ...

Is it possible to selectively process assets based on their type using Gulp and Useref?

Is it possible to selectively process css and js assets using gulp-useref based on the build type specified in the html tags? <!-- build:<type>(alternate search path) <path> --> ... HTML Markup, list of script / link tags. <!-- endbui ...

Setting border radius for the first child of li dynamically using Javascript

I am currently working on creating a navigation bar that features rounded corners for the first and last children within an unordered list. My goal is to utilize the onclick javascript function to dynamically assign these rounded corners directly in JavaSc ...

Utilize the data storage API within Next.js or directly in the user's

Struggling to store this ini file on either the server or client, any help would be greatly appreciated. Additionally, I would like to display the ini info in the browser so that clients can easily copy and paste the information. However, I seem to be fac ...

Converting JSON data into HTML format

I have been tasked with displaying a list of news articles on my webpage, and I have been provided with a link to a json file containing the necessary data. My goal is to convert the information in the json file into HTML format. Here is a preview of the ...

What is the process for transferring a file's contents to my server?

I am currently working on allowing users to import an OPML file that I parse server-side in my Rails application. However, I am facing difficulties as it appears that my server is not receiving the information correctly (neither the success nor error funct ...

Having trouble rendering Next.JS dynamic pages using router.push()? Find out how to fix routing issues in your

The issue I am facing revolves around the visibility of the navbar component when using route.push(). It appears that the navbar is not showing up on the page, while the rest of the content including the footer is displayed. My goal is to navigate to a dy ...

Error encountered while retrieving the cropped image, atob function was unable to execute

I am currently facing an issue with saving a cropped image in Chrome. When I try to save it, the download fails when using the Download button that I added to the page. I have successfully used ngx-image-cropper for cropping the image as intended. The cro ...

Attempting to imitate the hover effect of a scroll-down button

Looking for advice on creating a scroll down button with a hovering effect similar to the one found on this website - . Any tips or suggestions would be greatly appreciated. ...

What is the best way to adjust the padding on the left and right of the Bootstrap navbar logo and menu items?

I am currently facing an issue with the alignment of the logo and menu on my website. They are currently aligned to the far edges of the screen, and I would like them to remain a set percentage distance away from the extremes, rather than an absolute dista ...

exciting, showcasing a dependency map using svg within an html5 environment

I am working on creating a polygon background for my menu, which needs to be responsive in design. Here is an example of what I am trying to achieve: example image. Should I use JavaScript to listen for size changes and adjust the points for the polygon e ...

The Slick carousel code downloaded from their official website is malfunctioning

I found this code on slick's website, but it's not working for me. Can anyone spot what I might be missing? http://codepen.io/anon/pen/pyEddO <html> <head> <title>My Awesome New Website</title> <link rel="styles ...

Troubleshooting a CSS problem on a table filled with images - See attached screenshots for

I've been working on a project involving my phpmyadmin database generating a series of 6 images on my website. I've placed them in a table, but now I'm facing some challenges - even though it seemed simple at first! The goal is to display t ...

error in jquery when splitting

I encountered an issue while trying to split data for checkboxes. var ukuran = data['model'].ukuran_model; var cek = ukuran.split(",").join('], [value='), $inputs = $('input[name^=ukuran]'); $inputs.filter('[value=&a ...

Adjust the ZIndex on a div through interactive clicking

For my new project, I'm exploring a concept inspired by Windows 7. The idea is that when you double click on an icon, a window will open. If you keep double clicking on the same icon, multiple windows should appear. The challenge I'm facing is im ...