Uniform selection frame width across nested list elements

I want to ensure that the width of the selection frame for all nested ul li elements is consistent, just like in this example.

When hovering over an element (making the entire line clickable), I don't want any space on the left. Currently, I am using an AngularJS recursive directive to generate this list, which can vary in depth.

If you check out what I have so far, you'll see that I haven't been able to find a solution yet.

This is how my CSS looks:

div[data-tree-model] li span:hover {
   background-color: #D7D7D7;
   border: 1px solid #A2A3A6;
   display: block; 
}

div[data-angular-treeview] {
   -moz-user-select: -moz-none;
   -khtml-user-select: none;
   -webkit-user-select: none;
   -ms-user-select: none;
   user-select: none;
   font-family: Tahoma;
    font-size:13px;
   color: #2E9BDB;
   text-decoration: none;
   font-weight: bold;
}
div[data-tree-model] ul {
   margin: 0;
   padding: 0;
   list-style: none;
   overflow: hidden;

}
div[data-tree-model] li {
   position: relative;
   padding: 0 0 0 20px;
}
div[data-tree-model] li span {
   cursor: pointer;
   white-space: nowrap;
   border: 1px solid transparent;
   display: block;
   width: 100%;
}

Here is the template for the directive:

//tree template
var template =
    '<ul>' +
       '<li data-ng-repeat="node in ' + treeModel + '">' +
          '<span href="#" data-ng-class="{\'selected\': node.selected == true , \'collapsed\': node.' + nodeChildren + '.length && node.collapsed, \'expanded\': node.' + nodeChildren + '.length && !node.collapsed, \'folder\': node.' + nodeChildren + '.length}" data-ng-click="' + treeId + '.selectNodeLabel(node)" title={{node.' + nodeLabel + '}}>{{node.' + nodeLabel + '}}</span>' +
          '<div data-ng-hide="node.collapsed" data-tree-id="' + treeId + '" data-tree-model="node.' + nodeChildren + '" data-node-id=' + nodeId + ' data-node-label=' + nodeLabel + ' data-node-children=' + nodeChildren + '></div>' +
        '</li>' +
     '</ul>';

Answer №1

For a tree view that will have a depth of 3 levels, you can achieve it using this method. In order to make it work, in your CSS you should eliminate the padding below:

div[data-tree-model] li {
    position: relative;
   //padding: 0 0 0 20px;
}

Additionally, include the following CSS:

div[data-angular-treeview] > ul > li > span {
  padding: 0 0 0 20px;
}
div[data-angular-treeview] > ul > li > div > ul > li > span {
  padding: 0 0 0 40px;
}
div[data-angular-treeview] > ul > li > div > ul > li > div > ul > li > span {
  padding: 0 0 0 60px;
}
div[data-angular-treeview] > ul > li > div > ul > li > div > ul > li > div > ul > li > span {
  padding: 0 0 0 80px;
}

This approach is tailored for a 3-level deep tree structure based on the current HTML DOM constructed through your directive. :)

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

Manipulating the visibility of components by toggling on click events according to the existing state in ReactJS

Disclosure: I am still getting familiar with ReactJS I'm currently working on incorporating a dialog window for selecting a country/language on the initial page of my application. Here's the concept: There's a small flag button in the to ...

Different strategies for displaying a singular pie chart on multiple pages

I have implemented a pie chart on an HTML page and now I want to display this chart on multiple other HTML pages. Below is the JavaScript code for creating the pie chart: function piechart() { var chart; var legend; ...

Displaying WordPress plugin queries in a linked file

I have been working on developing a custom WordPress plugin that involves querying a database based on user input and then displaying the results in an HTML file with links. While I have managed to successfully display the HTML page, I am facing an issue w ...

ng-dialog: the selected value of the input radio button is not defined

While working with ng-dialog, I encountered an issue where the radio button value always ended up being undefined. Below is the dialog template: <script type="text/ng-template" id="flag-reasons.html"> <div style="padding:10px;"> & ...

The image fails to appear while creating a PDF in AngularJS using pdfmake

I recently started using a fantastic pdf printing library called pdfmake in my angularjs SPA to generate PDF files. Everything was going smoothly until I tried to include images in the PDF. Strangely, when I added images, nothing happened - no errors, no e ...

I would like to request information regarding PHP

I am attempting to retrieve information from a PHP file and insert HTML code into the <div id="1"..., but there are no errors showing and nothing is being inserted into the div. Could the issue be with the AJAX code or is it a problem within the HTML st ...

Manipulating deeply nested data using AngularJS forms

Having trouble parsing a model from a form with a select(ngOptions) and saving it to the database. The selected value isn't being parsed correctly. Any help would be appreciated. Here is the code snippet: View <section class="container" data-ng- ...

Can you explain the distinction between ' &:hover' and ' & :hover' pseudoclass selectors?

While styling a Material-UI Button, I encountered an unexpected behavior when adding hover effects. When using & :hover, only the inner span of the button was affected. However, when using &:hover, the desired style was achieved. What is the diff ...

Position the text alongside the thumbnail rather than in the center

In the current setup, my username text is positioned in the center of the view. I want to reconfigure it so that it displays directly to the right of the thumbnail. However, removing the alignItems: 'center', property from the item disrupts the e ...

Incorporate unique color variables from the tailwind.config.js file

I am working on a project using nextjs and typescript, with tailwind for styling. In my tailwind.config.js file, I have defined some colors and a keyframe object. My issue is how to access these colors to use as background values in the keyframe. Here is ...

What is causing the alt or title tags to not function properly in emails?

I am currently facing an issue with e-mail templates that include images. The problem arises from the fact that these images need to be downloaded before they can be displayed in the email. To work around this, I always use ALT and TITLE tags to provide de ...

Fading effect of Bootstrap JS on reducing content size

My quest for a toggle collapse button led me to this helpful link: https://getbootstrap.com/docs/4.0/components/collapse/ I found what I needed, but encountered an issue with the transition; clicking on the button immediately reveals my div. I desire a slo ...

Border with curved edges

Having an issue with content boundaries while using CSS rounded corners in Firefox. Here is the code snippet: Code <html> <head> <style> #outter { width: 200px; margin: auto; text-align: cent ...

Save updated tags only when the form is submitted in ngTagsInput

Can the sending of a new tag to the server be disabled after adding it to the input and saving it later by clicking a submit button? This is my Controller: vm.tags = []; $scope.loadTags = function (query) { return $http.get('api/tags?query=' ...

What is the best way to implement horizontal scrolling in a div with the "inertia" style?

I recently added horizontal scrolling to my website wikiprop.org, following a tutorial from another website. However, I noticed that my scroll does not have the same inertia/momentum effect where it continues scrolling after a swipe and gradually slows dow ...

Having trouble getting the carousel slider to function properly on meteor?

I am currently working on my portfolio page using Meteor, and I want to include a carousel slider gallery. The problem I'm facing is that while the first gallery works fine, the second one does not load correctly and just displays a list of pictures. ...

Steps to easily modify the color of Font Awesome stacked icons when hovering over them

I have incorporated two Font Awesome icons into my design: fa-circle-thin fa-user-plus These icons are stacked to create a circular icon appearance. <span class="fa-stack fa-sm"> <i class="fa fa-circle-thin fa-stack-2x"></i> <i c ...

Please explain the display property used in Bootstrap input groups

I have been working on implementing a button that toggles the visibility of a datepicker when clicked. <a class="btn btn-primary btn-lg mr-5" href="../Stores/stalls.html">Check Current Operating Stalls </a> <div style="vertical-align: t ...

jQuery inserts a closing tag before reopening it when applying .before()

I have the following HTML code: <ul> <div> <li>a</li> <li>b</li> <li class="break">c</li> <li>d</li> <li>f</li> ...

What is the best way to implement ng-model in conjunction with ng-repeat?

I created a form using ng-repeat, but I am struggling to incorporate ng-model into it. I attempted to use track by $index without success. While I found examples of using ng-model with values in an object, that's not what I'm looking for. I simp ...