AngularJS Treeview with Vertical Line Styling using CSS

Struggling with styling, I am attempting to create a tree view in AngularJS. Currently, I am facing an issue aligning vertical and horizontal lines for the tree items.

Check out my Codepen for reference.

<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Drag and drop angular tree</title>
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  <script src="https://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.2/angular.min.js"></script>
  <script src="https://rawgithub.com/angular-ui/ui-sortable/master/src/sortable.js"></script>  
  <style>

div[data-tree-model] ul {
  margin: 0;

  list-style: none; 
  border: none;
  overflow: hidden;
  position: relative;
  list-style: none;
  padding-left: 12px;
}

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

div[data-tree-model] li .expanded {
  padding: 1px 10px;
  background-image: url("http://cfile23.uf.tistory.com/image/205B973A50C13F4B19D9BD");
  background-repeat: no-repeat;
}

div[data-tree-model] li .collapsed {
  padding: 1px 10px;
  background-image: url("http://cfile23.uf.tistory.com/image/1459193A50C13F4B1B05FB");
  background-repeat: no-repeat;
}

div[data-tree-model] li .normal {
  padding: 1px 10px;
  background-image: url("http://cfile23.uf.tistory.com/image/165B663A50C13F4B196CCA");
  background-repeat: no-repeat;
} 

div[data-tree-model] li i, div[data-tree-model] li span {
  cursor: pointer;
}

div[data-tree-model] li .selected {
  background-color: #aaddff;
  font-weight: bold;
  padding: 1px 5px;
} 

div[data-tree-model] li::before, div[data-tree-model] li::after {
    content: "";
    position: absolute;
    left: -12px;
}

div[data-tree-model] li::before {
    border-top: 2px solid black;
    top: 9px;
    width: 4px;
    height: 0;
    padding-left: 4px;
    margin-left: 6px;
}

div[data-tree-model] li::after {
    border-left: 2px solid black;
    height: 100%;
    width: 0px;
    top: 0px;
    margin-left: 5px;
}

div[data-tree-model] ul > li:last-child::after {
    height: 8px;
}

div[data-tree-model] li:fisrt-child::after {
 height: 0px;
}

</style>
</head>
<body>
  <div ng-app="myApp">
  <div ng-controller="myController">
    <!-- <div>{{roleList}}</div></br> -->
      <div class="clt"
      data-angular-treeview="true"
      data-tree-id="mytree"
      data-tree-model="roleList"
      data-node-id="roleId"
      data-node-label="roleName"
      data-node-children="children" >
    </div>
  </div>
</div>
</body>
<script>
(function(){

  //angular module
  var myApp = angular.module('myApp', ['angularTreeview', 'ui.sortable']);

  //test controller
  myApp.controller('myController', function($scope){

    //test tree model 1
    $scope.roleList1 = [
        { "roleName" : "User", "roleId" : "role1", "children" : [
          { "roleName" : "subUser1", "roleId" : "role11", "children" : [] },
          { "roleName" : "subUser2", "roleId" : "role12", "children" : [
            { "roleName" : "subUser2-1", "roleId" : "role121", "children" : [
              { "roleName" : "subUser2-1-1", "roleId" : "role1211", "children" : [] },
              { "roleName" : "subUser2-1-2", "roleId" : "role1212", "children" : [] }
            ]}
          ]}
        ]},

        ...

</script>
</html>

Seeking assistance in aligning vertical lines of the tree view correctly. Need them to touch the folder open-close images and corners accurately. Also aiming for an open end at the first child node. Similar to this example:

If you have any suggestions or solutions to achieve this design, your input would be greatly appreciated. Thank you!

Answer №1

Make a substitution

div[data-tree-model] li::before {
    border-top: 2px solid black;
    top: 9px;
    width: 4px;
    height: 0;
    padding-left: 4px;
    margin-left: 6px;
}

with

div[data-tree-model] li::before {
    border-top: 2px solid black;
    top: 8px;
    width: 4px;
    height: 0;
    padding-left: 4px;
    margin-left: 5px;
}

and you will receive instead of

Do these changes meet your expectations?

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

The module instantiation in AngularJS encountered an error

Currently learning AngularJS and attempting to develop an authentication service, but encountering an error. Error: [$injector:modulerr] Failed to create module flujoDeCaja: [$injector:modulerr] Module auth failed to instantiate: [$injector:nomod] Module ...

Maintain the div height as the image loads

Is there a way to prevent the collapse of the .img-container while an image is loading? Currently, when the image takes a few seconds to load, the container collapses and only expands to full height once the image has loaded. I would like the container to ...

Incorporating Cascading Style Sheets (CSS) to

I'm looking to style my form with CSS but I'm unsure of the process. Currently, the form is generated using PHP and MySQL, and in the browser it appears like this: http://gyazo.com/5d099ead9bd6ea83859a5114b2438748 I want to align the text and dr ...

Exploring the jungle. Cursor acting strange while dragging

I am currently working on implementing drag-and-drop functionality in my project, utilizing slip.js from slip.js. To enhance the cursor during dragging, I have assigned class="draggable" to each draggable <tr>. The CSS code for this class is: .drag ...

"Implementing a search bar feature using HTML, CSS, and

My attempt to implement a search bar CSS from CodePen is not working properly in React. Even though I used the exact code provided, the search bar seems to be buggy. If you want to take a look at the code sandbox for better reference, you can visit: https ...

Exploring the functionality of the MediaPicker property editor within a custom property in Umbraco

I am currently working on a custom property editor that utilizes the media picker. My controller code is as follows: angular.module("umbraco").controller("My.MediaCropperController", function($scope, dialogService) { $scope.mediaPicker = { ...

The placeholder text in the matInput field is not being displayed

As a newcomer to Angular, I am facing a challenge that has left me unable to find a solution. Below is the code snippet in question: <mat-form-field> <input matInput placeholder="ZIP" style="color:red;"> </mat-form-field& ...

Retrieve information from a database using AngularJS for a form

When visiting the front page, you will see two options: 1. Create New 2. Edit If you choose option 1, it will take you to index.html. Option 2 should navigate to index.html with pre-loaded data from the database. // Retrieving data from the database ...

"Troubleshooting problem with AngularJS service scope following a directive's event listener callback

I am currently facing an issue while trying to incorporate an event listener in my angular directive coupled with a service. The problem lies in the scoping as I require 'this' to point to the 'this' of my service. At present, within ...

Is it feasible to decrease the lateral margins of Bootstrap's container without the need for custom CSS? If so, what is the method?

My web page includes several screenshots to illustrate the issue I am facing. One of my challenges is the scroll bar below the table, which I find displeasing. In an attempt to resolve this, I decided to adjust the lateral margins slightly. Here's a s ...

The AngularJS gettext module encounters an issue where the gettextCatalog.getString() method is not properly translating in the controller

Currently, I am utilizing the gettext module for Angular to manage my translations. So far, this setup has been functioning nearly flawlessly. My current situation involves working with 2 controllers. One is named basecontroller while the others are speci ...

Paginated tables only sort the data on the current page

Setting table headers: <th class='header'> <a href="" ng-click="orderByField='success'; reverseSort = !reverseSort"> Successes <span ng-show="orderByField == 'success'"><span ng-show="!reverseSort ...

While utilizing a dynamic PHP navigation header, the nested divs are shifting below the container div

After successfully implementing a dynamic PHP header on my site, I encountered issues when trying to incorporate the remaining content within the container div along with the header div. The additional content is not displaying inside the container but is ...

Testing the functionality of a service using unit tests that involve a promise

I have developed a service for a current project and now I am working on writing a unit test for it. Below is the code snippet for the service: angular.module('services').factory('Authorization', ['$q', 'Refs', func ...

Is it possible to access the CSS property from an external CSS file even when inline styles are used?

Is there a way to retrieve the css property from an external source using JavaScript or jQuery even if inline styles are applied to the same element? Here's an example: <div id="my" style='left:100px'>some content</div> <styl ...

The image filter plugin is functioning properly in one project, however, it is not working in

After successfully using a plugin from w3schools to filter elements in one project, I encountered an issue when attempting to implement it in another project. Here is the link to the problematic code pen: https://codepen.io/zakero/pen/mZYBPz If anyone ca ...

What is the process for calculating and determining the exact area the div should be released?

I am currently developing a drag-and-drop application using only Javascript. I have successfully implemented the dragging functionality, allowing elements to be moved randomly within the page. However, I now face the challenge of creating a drop zone with ...

Troubleshooting: Why Your Angular Data Binding is Failing

I am integrating a WCF REST service with an AngularJS application. My goal is to retrieve account information based on the account number provided, however, I am encountering an issue where the text "Account_Type" is displayed three times before showing th ...

An issue has occurred with the HTTP request to a PHP file in Angular

When attempting to send an http request to my php file, I encountered the following error message Possibly unhandled rejection: {"data":null,"status":-1,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":" ...

Unexpectedly, Angular 1.5 is providing a response status of NULL (-1) instead of 503 because of cors issues

When using Angular 1.5.5, I encountered a response status of 503 along with a No Access-Control-Allow-Origin header error in the browser. Strangely, the $http service returned a status of NULL (-1). Is there a method to extract the precise 503 error with ...