Is there a way to ensure that a DIV displays inline and aligned at the same distance from the right in my HTML layout?

Within my HTML template, I have a collection of categories and subcategories. Each category can contain anywhere from 0 to n subcategories.

I am currently displaying these using nested for loops:

Category 1
  Subcategory 1
  Subcategory 2
Category 2
  Subcategory 3
  Subcategory 4
  Subcategory 5

Additionally, I have drop-down menus specific to each category and subcategory.

Despite my efforts, I cannot get the drop-downs to remain on the same line as the corresponding category or subcategory. Here is how they currently appear:

Category 1                 
menu
Subcategory 1       
menu
Subcategory 2       
menu
Category 2                
menu
Subcategory 3       
menu
Subcategory 4       
menu
Subcategory 5       
menu
Category 3                 
menu

To achieve the desired layout - with drop-downs aligned in the same row as their respective category or subcategory - with fixed offsets, the structure should resemble this:

Category 1                 menu
  Subcategory 1       menu
  Subcategory 2       menu
Category 2                 menu
  Subcategory 3       menu
  Subcategory 4       menu
  Subcategory 5       menu
Category 3                 menu

The provided HTML showcases this dynamic:

<div class="well">
  <div style="overflow-y: scroll; overflow-x: hidden; height: 500px;">
    <ul class="nav nav-list">

      {% for category in page_category %}
        <li><label class="tree-toggler nav-header">Category:{{ category.name }}
          <div class="dropdown">
            <a id="dLabel" data-target="#" href="http://example.com" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
              <span class="glyphicon glyphicon-cog">Options</span>
              <span class="caret"></span>
            </a>
            <ul class="dropdown-menu" aria-labelledby="dLabel">
              <li> <a href="{% url 'subcategory_new' pk=category.id %}">Create subcategory</a></li>
              <li> <a href="{% url 'subcategory_new' pk=category.id %}">Delete</a></li>
              <li> <a href="{% url 'subcategory_new' pk=category.id %}">Edit</a></li>
            </ul>
          </div>

          </label>

          <ul class="nav nav-list tree">

            <lh>Sub Category</lh>

            {% for field in category.subcategory_set.all %}

              <li>#{{ field.id }} {{ field.name }} - {{ field.description }} {{ field.keywords }}
                <div class="dropdown">
                  <a id="dLabel" data-target="#" href="http://example.com" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                    <span class="glyphicon glyphicon-cog">Options</span>
                    <span class="caret"></span>
                </a>

                <ul class="dropdown-menu" aria-labelledby="dLabel">
                  <li><a href="{% url 'subcategory_new' pk=category.id %}">Create subcategory</a></li>
                  <li><a href="{% url 'company_new' %}">Delete</a></li>
                </ul>
                </div>
              </ul>
              </li> <li class="divider"></li><!--category li closing-->

              {% endfor %}
            </ul>
            </li>
          {% endfor %}
          </ul>
        </div>
        </div>

The script used to toggle visibility is as follows:

$(document).ready(function () {
    $('label.tree-toggler').click(function () {
        $(this).parent().children('ul.tree').toggle(300);
    });
});

If you have any alternative design ideas, suggestions, or recommendations, please feel free to share them. I am utilizing the Django Framework alongside Bootstrap and JQuery for this project.

Answer №1

In my opinion, by incorporating the class pull-right into the existing classes of dropdown, you can align it to the right side:

<div class="dropdown pull-right">

To achieve an indentation from the right for the subcategories, simply apply a margin-right to those particular elements.

.nav-list .nav-list .dropdown {margin-right: 10px;}

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

Can a Bootstrap vertical column be made sticky without defining its position?

I'm attempting to replicate the effect of a sticky column positioned to the right of some text, similar to what is seen on the Bootstrap website. Below is the code I've been working with: <nav class="col-sm-4 col-md-4" data-spy="affix" dat ...

What purpose does the symbol '$' serve in React component properties?

While delving into the world of styled-component, I encountered some difficulties with the 'adapting based on props' aspect. import './App.css'; import styled from 'styled-components' const PrimaryButton = styled.button` co ...

What is the best method for encrypting a file using node.js?

I am in the process of finding a way to encrypt various types of files like txt, mp3, or any other file in node.js while utilizing socket.io. My goal is to develop an application that can securely send files to another client, so I wish to encrypt the file ...

invoking a Java function via AJAX

After spending some time trying to grasp this concept, I'm still struggling to fully understand it. Let's take a look at the Servlet code snippet for "ProcessNurseApp": if (dbm.CheckExRegNumber(Candidate.getRegNumber()) == true) { / ...

Tips for displaying AJAX response on a new webpage

I am currently working on a mobile app using Phonegap and Intel XDK. My goal is to display an AJAX response on a new HTML page. After doing some research online, I came across the solution of using window.open();. However, this method did not work for me ...

Ways to create a downward expanding navigation menu when collapsed

Trying to accomplish the following, please refer to the image below. I am looking to have the yellow bar extend down when the collapsed menu is open. Currently, the navigation links are hidden behind the logo as shown in the second image below. https://i. ...

Issues with implementing a Bootstrap dropdown list in a Django HTML template

I'm having trouble implementing Bootstrap in my Django project's shared HTML file. The dropdown list isn't functioning properly despite trying various approaches, including using CDN and local Bootstrap files. When I click on the dropdown li ...

Improving the efficiency of jQuery code when using the '.on' method

Is there a significant performance implication from the code below? $("body").on('click','#id',function () { //code to be executed }); If yes, I would appreciate an explanation as to why. ...

Undesirable gap found within the bootstrap columns

I'm experiencing issues with the design of my form controls in Bootstrap. I have divided the screen into three columns, with each column being 4 md wide. The General Agreement control is defined as col-md-8 to span across. I'm unsure why there is ...

What is the best method to add an overlay div onto another div when hovered, with a grid-style layout?

I attempted to create a grid-like design where each div would display an overlay on hover. The overlay div includes two buttons that should be centered. Although I believe the logic of my code is correct, the position of the buttons and overlay is not ce ...

Selecting the Right JSON File for Your D3 Force-Directed Graph

Currently, I am working with a force-directed graph and I would like the ability to switch between different JSON files dynamically, consequently altering the data displayed in the graph. While I can manually change the file name in the HTML code, my goal ...

Retrieving parameter values from a URL using jQuery to validate a radio button in PHP

Hello, I have a form with several radio buttons that I use to filter my data. I am interested in figuring out how to make a radio button checked based on the URL. Can anyone provide guidance on how to achieve this? Form: <form method="post"> <di ...

In search of a highly efficient webservices tutorial that provides comprehensive instructions, yielding successful outcomes

I've reached a point of extreme frustration where I just want to break things, metaphorically speaking, of course. For the past week, I've been trying to learn how to create a web service using C# (whether it's WCF or ASMX, I don't rea ...

Display the Django data in a JS static file while escaping any special characters

I am using a django banner to import some data into the javascript of my page and I need help resolving an issue. Here is a simple example: <script> console.log({{data|escapejs}}) </script> Unfortunately, this code does not work when placed in ...

Having trouble connecting parameters between Django and Vue components

I'm having trouble connecting Django REST with Vue. When I try to call the API from the client, I get the following error message: Not Found: /api/private/ [16/Sep/2018 13:18:59] "GET /api/private/?city=London HTTP/1.1" 404 2129 This is the code tha ...

Locate a string containing a series of words separated by a character, with the last word being able to end with any combination of characters through the use of regex

Here are some words to consider: const words = ["apple", "orange", "tomato"] const str = "apple.orange.tomato.$COULD_$_BE_ANY_STRING_HERE" I am in search of a regular expression to verify the format of this string. ...

none of the statements within the JavaScript function are being executed

Here is the code for a function called EVOLVE1: function EVOLVE1() { if(ATP >= evolveCost) { display('Your cell now has the ability to divide.'); display('Each new cell provides more ATP per respiration.'); ATP = ATP ...

Using a PHP variable in a jQuery.ajax call

I have a form on a php page where users input data that is then saved into a .txt file. Currently, the form works fine - when filled out and submitted, users are taken to a confirmation page and their data is stored in the .txt file. However, I am lookin ...

Issue with Function returning undefined rather than a numeric value

I'm currently working on a JavaScript function that calculates a bill. Below is the code snippet: let bill = () => { Customer .findOne({stb_no: "34BDFA64E31F"}) .then(result => { Plan.findById(result.plan).populate('channel ...

What is the best way to handle an AJAX JSON response in AngularJS?

Need help with extracting properties from a JSON object returned by a REST service in AngularJS? Want to parse the firstName, lastName, and other attributes from the JSON response? Check out the code snippets below for guidance. Here is an example of an A ...