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:

https://i.sstatic.net/u5TaZ.png

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 https://i.sstatic.net/6ibLx.png instead of https://i.sstatic.net/jn0Di.png

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

Is it possible to dynamically update the currency symbol in an AngularJS filter?

Query Background: I have a dropdown menu with 4 country options: UK (United Kingdom), US (United States), FR (France), GER (Germany). Depending on the selected option, I need to filter a price in my Controller's Scope object to display the correct cu ...

I encountered an issue with my shopping cart while using ReactJS

this is the App.js file import React from "react"; import ListProduct from "./listProduct"; import ListOrder from "./listOrder"; import pizza from "./pizza.jpg"; import './style.css' import { Container,Row,Col,Button } from 'react-boo ...

Troubleshooting Vue 3 Options API custom element with non-functional Bootstrap js files

Having trouble incorporating Bootstrap 5 into a Vue 3 Options Api custom element? Check out my setup below: import { defineCustomElement } from 'vue' import 'bootstrap/dist/js/bootstrap.bundle' import App from './App.ce.vue' ...

trouble with padding on cards using vue-bootstrap

I have been working on creating a card component with Vue Bootstrap, but I've run into an issue. The card header and body seem to have excessive padding around them. If I remove the b-card element and only use b-card-header and b-card-body, it looks l ...

What could be causing ng-submit to not successfully transmit data?

I'm currently going through this Yeoman tutorial, but I'm encountering some issues. The new todo is not being added to the $scope.todos as expected, and I'm struggling to identify the reason behind it. You can access the code here: Upon c ...

Attempting to connect CSS to an HTML document within a Django development project

Directories Here is a photo of my directories. I am currently trying to utilize sudokuStyle.css in sudoku_board.html, but for some reason it does not appear to be linking properly in my HTML file. Below is the code snippet from my head section: {% load st ...

Arranging rows and columns in Bootstrap 3 for small screens

My layout is structured as follows: <div class="container"> <div class="row"> <div class="col-md-8> <div class="row"> <div class="col-md-12"> box 1 & ...

What could be causing my $resource error handler not to be invoked even though I have a responseError interceptor set up?

As I develop my first Angular application, I've encountered a challenge. Within my AngularJS resource, I call the .get method with both success and error callbacks, like this: var new_uptime = Uptime.get({}, function(){ console.log("new_uptime", ...

Having trouble getting the sorting/search function to work with a click event to display content. It seems to only work with a single item - possibly an issue with the

Creating a function that involves multiple boxes with a search function. The search function is working for the most part, but when clicking on a result, certain content should display. function filterFunction() { var input, filter, ul, li, a, i; ...

Ensuring DIVs are completely contained within their parent DIV using Fullscreen CSS and a height of

I found a nearly-perfect design using the code below: https://i.sstatic.net/56i2E.png This code provides the layout mentioned: <!DOCTYPE html> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="http://maxcdn. ...

Creating a flexible Bootstrap 3 layout that responds to the size of a div, not just the screen

Having a web page layout with a main content area and a fixed-width sidebar is proving to be a challenge. I want the content displayed in both sections to be responsive, adjusting based on the size of their respective parent divs rather than the screen siz ...

Challenges with Image Placement and Alignment

Having trouble with the sizing of my image in the skill portion of my website. The clouds and mountains look fine, but for some reason, the image isn't the same size. Additionally, the text "full stack developer" is not centered under my name anymore ...

Guide on incorporating Activiti into an AngularJS application

Looking for guidance on implementing business process management in application development using AngularJS and REST. After researching, the options I found are Activiti, Camunda and BonitaBPM. Does anyone have experience with these tools? Any recommendat ...

Creating a bold portion of a string

My task involves dynamically creating <p> elements within a div based on the contents of my codeArray, which can vary in size each time. Instead of hard-coding these elements, I have devised the following method: for(i=1;i<codeArray.length;i++) ...

Looking to populate my HTML fields with values

When attempting to edit, the id is being passed but the data fails to populate in the HTML fields. Please refer to this image. Index @{ ViewBag.Title = "AngularJs Tutorial"; } <style> </style> <h2>AngularJs Tutorial : CRUD operatio ...

tips for moving a button 2 pixels up or down in position

How can I adjust the position of my button by a specific number of pixels up or down from where it currently is? Can you provide guidance on how to find the current location? Thank you in advance. ...

What is the deal with CSS relative magnification?

I am currently utilizing a PHP styleswitcher along with alternate stylesheets in an attempt to replicate the functionality of browser zoom (done using keyboard shortcuts cmd-plus or ctrl-plus). At the moment, when clicking on the "zoom in" graphic, it is ...

I am experiencing issues with the Bootstrap responsive menu not functioning correctly on my template

While working on this Bootstrap 3 template, I observed that the default responsive menu is not functioning properly when I resize my browser for testing. I have previous experience designing responsive templates that work well, but this particular templat ...

Tips for improving performance with ng-repeat directive?

I have encountered some performance issues while using socket.io with the ng-repeat directive in Angular. The application slows down significantly when receiving a large amount of data from the backend, making it impossible to interact with the app. What w ...

Tips for effectively resizing an iframe within a grid layout

Task Tailwind React When adjusting the scale of an iframe, it disrupts its position within the grid. Expected Outcome: The iframe should maintain its position after scaling, but with a smaller size. Current Behavior: The iframe's position is be ...