Replicating the functionality of one class to another class in Twitter Bootstrap

In the Twitter-bootstrap framework, it searches for the active class within an li element to determine which navigation element should be highlighted.

However, I am using django-cms, which by default uses a selected class to indicate the same thing (i.e. "this tab is where you currently are"). Is there a way to achieve something like this:

class "selected" = class "active"

The li element generated by django-cms is created using the template tag show_menu, so I do not have direct access to the element to manually add the active class myself.

Answer №1

There is an option to assign multiple CSS classes to your HTML elements for styling purposes...

<div class="highlighted visible">
    ...
</div>

Answer №2

Consider adjusting the bootstrap mixin to search for "selected" rather than "active" - this approach prevents overloading your markup with superfluous classes.

Answer №3

In the scenario where you have your own server hosting Twitter Bootstrap instead of linking directly from Github, a modification to the Bootstrap .active class selector could involve updating it to:

.active, .chosen {
    ...
}

If this is not feasible, an alternative approach would be to utilize LESS CSS, which allows for the desired type of inheritance whether executed on the client side or server side.

.chosen {
    .active;
}

Answer №4

To avoid duplicating a class, simply create a new class and add the desired styles along with the .active class. For example:

.navigation a:hover, .navigation .active a,  .navigation .chosen a {
  background-color: #f5f5f5;
}
.navigation .active a, .navigation .chosen a {
  color: #999999;
  cursor: default;
}

This approach allows the .chosen class to inherit all properties from the .active class.

Answer №5

If you're looking for a simple solution, one way I've discovered is to set a custom menu template in the show_menu function.

{% show_menu 0 100 0 0 "bootstrap_menu.html" %}

For the bootstrap_menu.html file, you can start with the original django-cms menu template, duplicate it, and ensure that it also adds the 'active' class:

{% load menu_tags %}
{% for child in children %}
    <li class="{% if child.selected %}selected active{% endif %}{% if child.ancestor %}ancestor{% endif %}{% if child.sibling %}sibling{% endif %}{% if child.descendant %}descendant{% endif %}">
        <a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}">{{ child.get_menu_title }}</a>
        {% if child.children %}
            <ul>
                {% show_menu from_level to_level extra_inactive extra_active template "" "" child %}
            </ul>
        {% endif %}
    </li>
{% endfor %}

You can locate the django-cms menu template in the ../menues/templates/menu directory within your site packages if you installed it via pip/easy_install, etc.

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 there a way to apply the style property only when a component is hovered in Next.js?

I would like the ability to hover over a component and have it display with unique CSS characteristics. For instance, if I hover on item A, I only want item A to stand out from the rest. Currently, I am using this method of changing the element's bac ...

Using the onclick event in JavaScript to create transition effects for swapping images

I am working on a website where I display 3 images. Instead of redirecting the users to a new page, I want to keep them on the same page. Question: How can I implement a functionality where clicking a <button> will display 3 new images in the view w ...

Two floating elements collide as the first one drifts over the second

I am working on a simple webpage that should take up the entire browser window. There are only two elements in it, but the issue is that the second element is being overlapped by the first. form { background-color:#996600; width:30%; height:1 ...

The Vue Swiper does not support inline containers in my code

I am facing an issue with the layout of my simple swiper in my vue app. The containers are not inline as expected, causing the second one to appear under the first. Additionally, I am struggling with making the slider element visible only within the viewpo ...

CSS translation animation fails to execute successfully if the parent element is visible

Inquiries similar to this and this have been explored, but do not provide a solution for this particular scenario. The objective is to smoothly slide a menu onto the screen using CSS translation when its parent is displayed. However, the current issue is ...

Learn how to dynamically add a class to an element when hovering, and ensure that the class remains even after the mouse has

I'm facing difficulty with this task - when hovering over elements, an active class should be added to them. However, when moving the mouse to another section, the active class should remain on the last element hovered. Additionally, the first block s ...

Is it possible to create this layout using Bootstrap 5? I want to stack spans, with one inside the container and one outside

Trying to achieve a specific design using Bootstrap 5.3. https://i.sstatic.net/STifm.jpg This design should be placed over the showcase, with the following code for the showcase displayed below: <div class="showcase d-flex flex-column"&g ...

Is there a way to adjust the height of one div based on the height of another div in Bootstrap?

I am experimenting with a Bootstrap example featuring a table in the left column and 4 columns in 2 rows in the right column. Check out the code below: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css ...

What is the best way to incorporate a background image that complements my content?

I'm currently working on revamping my friend's windsurf club website. The issue I'm facing is with trying to achieve a more elegant appearance by positioning a background image behind the <h1> and <h2> elements. Currently, I have ...

Updating a Django query dynamically based on a string field

Is there a way to update a record based on a string-determined field? This is the model structure I am working with: class Wallet(models.Model): user_id = models.IntegerField(blank=True, null=True) wallet1 = models.DecimalField(max_digits=15, dec ...

Unable to adjust column width and margin in fixed layout mode

I am having trouble setting the column width for a specific column in my table. The table has a layout=fixed and width=100%. I tried setting max-width=300px for one of the columns, but it seems like all columns are evenly distributed within the table. Unfo ...

Encountering the HTTP Error 502 Bad Gateway when running Django and Satchmo with nginx and FastCGI after a period of time

Recently, I set up a new Satchmo store on a Linux Debian 6 distribution. The standard Django development server was running smoothly, but when I switched to production mode with nginx + FastCGI, I started encountering a "502 Bad gateway" error after some t ...

Tips for eliminating the margin in a bootstrap navigation bar when hovering?

Here is the Navigation Bar that I customized, along with the CSS code I used to override the Bootstrap styling. Below are images showing the current output and the expected output. <div class="row fixed-top"> <div class="col-md-1"></div> ...

What is the ideal location for storing my CSS files?

I have a medium-sized website that shares a common header/footer, and each page has its own specific layout file. The common header/footer is stored in a separate html file, but I am struggling with where to place the CSS file because the link element in f ...

"Font Awesome icons are only visible online on the -dev website, not visible anywhere

I followed the recommended steps on Fontawesome's official site to install the fontawesome library. I used the following command: npm install --save-dev @fortawesome/fontawesome-free For production purposes, I included the following code in my index ...

The communication between Ajax and django views appears to be incomplete as the data is

Just completed the necessary parts. Being a beginner, please excuse any shortcomings in the question :). Below is my Html code: <div class="form-group row pt-3 d-flex justify-content-center"> <div class="col-sm-10 d-fle ...

How do I align the Close button to the right in a Bootstrap 5 toast message?

To create a Bootstrap 5 toast, I use the following code: <div id="liveToast" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true"> <div class="toast-header"> ...

Understanding the discrepancy between Django's admin `save_model()` method and the `post_save` signal

When it comes to my application, I find myself needing to perform additional tasks when a model is saved through a form. Specifically, I need to include a value in another model based on specific conditions present within the form. As I navigate this proc ...

Layer several divs inside a main div

I'm grappling with a simple issue and could use some help to resolve it. Utilizing bootstrap, below is my CSS and div structure. How can I achieve an overlap of DIV 1, DIV 2, and DIV 3? Essentially, I want to position them on the same level, one behi ...

What is the best way to combine a radio button with a dropdown button in Bootstrap?

Hi there, talented developers! I'm attempting to create a design with a combination of radio buttons and dropdown menus using Bootstrap, similar to what is achieved with bootstrap input-group(Buttons with dropdowns). The twist in my design is that i ...