Focusing solely on a particular category in EJS

I am struggling with this code snippet.

HTML:

<header<% if (  current.source === 'features' ||  current.path[0] === 'index' ||  current.source !== 'customers' ) { %> class="header-white"<% } %>>
<div class="row">
    <div class="small-3 columns">
        <div class="logo">
            <a href="/">
                <svg class="handsontable-logo">
                    <use xlink:href="#handsontable-logo"></use>
                </svg>
            </a>
            <a href="//github.com/handsontable/handsontable" id="github-star" class="star-counter" target="_blank">
                <svg>
                    <use xlink:href="#github-squid"></use>
                </svg>
                <div class="github-star">
                    <div class="triangle"></div>
                    <div data-bind="starsCount">-</div>
                </div>
            </a>
        </div>
    </div>

    <div class="small-9 columns text-right">
        <nav class="mobile-inactive">
            <a href="#" id="mobile-nav-menu">
                <svg>
                    <use xlink:href="#open-mobile-nav"></use>
                </svg>
            </a>
            <ul>
                <li class="mobile-only"><a href="/">Home</a></li>
                <li><a href="/features.html">Features</a></li>
                <li><a
                       href="/examples.html?manual-resize&manual-move&conditional-formatting&context-menu&filters&dropdown-menu&headers">
                        Examples
                    </a></li>
                <li><a href="/download.html">Download</a></li>
                <li><a href="/pricing.html">Pricing</a></li>
                <li><a href="/customers">Case studies</a></li>
                <li><a href="/developers.html">Developers</a></li>
                <li class="mobile-only"><a href="/resellers.html">Resellers</a></li>
                <li class="mobile-only"><a href="/blog/">Blog</a></li>
                <li class="mobile-only"><a href="/contact.html">Contact</a></li>
                <li class="news">
                    <svg>
                        <use xlink:href="#bell"></use>
                    </svg>
                </li>
                <li><a href="//my.handsontable.com/sign-in.html"
                       class="btn size-small bg-green-light bg-lighten text-white">
                        Sign in
                    </a>
                </li>
            </ul>
        </nav>
    </div>
</div>

SCSS:

header {
@include absolute-top-left (0, 0);
width: 100%;
padding: 34px 0 0;
z-index: 1;

.logo {
@include relative-top-left (-3px, 0);

@media only screen and (min-width: $largeWidth) {
  @include relative-top-left (10px, 0);
 }

svg {

  &.handsontable-logo {
    @include rectangle (130px, 25px);
    fill: $baseGray;
  }
}
}

 /* Begin: This allows to stretch the mobile menu to 100% of width of the viewport */
 & > .row > .columns:last-child {
position: static;
 }
  /* End */

nav {

& > a {
  @include absolute-top-right (4px, 5px);
  padding: 20px;
  display: block;
  z-index: 11;

  @media only screen and (min-width: $largeWidth) {
    display: none;
  }

  svg {
    @include square (28px);
    fill: $baseGray;
  }
}

ul {
  display: none;

  @media only screen and (min-width: $largeWidth) {
    display: block;
  }

  li {
    padding: 0 19px;
    display: inline-block;

    &:last-child {
      padding-right: 0;
    }

    &.mobile-only {
      display: none;
    }

    &.news {
      padding-right: 32px;
      position: relative;

      svg {
        @include square (18px);
        @include relative-top-left (4px, 0);
        fill: $baseGray;
      }

      #HW_badge_cont {
        @include absolute-top-left (0, 13px);

        #HW_badge {
          @include square (12px);
          @include relative-top-left (0, 0);
          line-height: 13px;
          background-color: $brandRedActive;

          &.HW_softHidden {
            opacity: .4;
            background-color: $brandVibrantGreenActive;
          }
        }
      }
    }

    a, a:hover, a:active, a:visited {
      font-size: 13px;
      color: $baseGray;
    }

    a:hover {
      color: $darkGray;
    }

  }
}
}

  /* Menu visible only on mobile devices */
 nav.mobile-active {

@media only screen and (min-width: $largeWidth) {
  display: none;
  }

& > a {

  svg {
    fill: $darkGray;
  }
}

ul {
  @include absolute-top-left (12px, 2%);
  width: 96%;
  padding: 66px 0 8px;
  display: block;
  text-align: center;
  border-radius: 4px;
  z-index: 10;
  box-shadow: 0 3px 18px rgba(0, 0, 0, 0.15), 0 3px 18px rgba(0, 0, 0, 0.15);
  background: #fff;

  li {
    width: 49%;
    padding: 10px 0;

    &.mobile-only {
      display: inline-block;
    }

    a, a:hover, a:active, a:visited {
      font-size: 18px;
      color: $brandBlue;

      &.btn {
        width: 100%;
        color: #fff;
        font-size: 18px;
      }
    }

    &:last-child {
      width: 90%;
      padding-top: 40px;
    }

    &.news {
      display: none;
    }
  }
}
 }

 &.header-white {

.logo {

  .github-star {
    border: 1px solid $darkWhite;
    color: $darkWhite;
    font-weight: 600;

    .triangle {
      border-right-color: $darkWhite;
    }
  }

  svg {
    fill: $darkWhite;
  }
}

a, a:hover, a:active, a:visited {
  color: #fff;
}

a:hover:not(.btn) {
  color: $brandFeatherBlue;
}

svg, .news svg {
  fill: #fff;
   }
 }
}

The issue I'm facing is that I need to change the navigation color specifically for the customers page.

The complication arises when all subpages within the customer's category also inherit the modified navigation style.

Therefore:

customers === white
| subfolder === white
| subfolder === white
| subfolder === white

To maintain consistency, I want the subfolders within the customer's directory to retain the original navigation color.

If anyone can provide assistance, I would greatly appreciate it as I currently do not have expertise in JavaScript but am eager to learn.

Answer №1

Condensing it down to the important parts, here is your SCSS code:

header {
  &.header-white {
    a, a:hover, a:active, a:visited {
      color: #fff;
    }
  }
}

This will change all your links to white.

If this pertains to your 'customers' section:

<li><a href="/customers">Case studies</a></li>

You can differentiate it by adding a class:

<li><a class="customers" href="/customers">Case studies</a></li>

Then adjust the CSS as needed:

header {
  &.header-white {
    a.customers {
      &, &:hover, &:active, &:visited {
        color: #fff;
      }
    }
  }
}

Answer №2

Issue resolved:

I realized I had been approaching the problem incorrectly by trying to link the exact path like this:

 <header<% if (  current.source === 'features' ||  current.path[0] === 'index' ||  current.source !== 'customers' ) { %> class="header-white"<% } %>>

Instead, all I needed to do was determine the specific length of the link, as shown here:

 <header<% if (  current.source === 'features' ||  current.path[0] === 'index' || current.path[1] === 'index' ) { %> class="header-white"<% } %>>

This solution worked for me, the main challenge was identifying the names and lengths of subpages.

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

Using PHP to dynamically update image source upon clicking an upload button:

Is it possible to dynamically display a new image after uploading it using an ajax-upload script on a 'edit product' page for a shop products? On load, all thumbnails are fetched from the DB but when a user uploads a new file, I want the new imag ...

Dropdown menu is not positioning correctly over other elements on the webpage

After researching multiple stack overflow questions and attempting various solutions, I still haven't been able to resolve my issue. Please refrain from marking this question as a duplicate. The problem I am facing is that my dropdown menu is not ap ...

How to keep jQuery horizontal submenu open when clicking on the menu

Seeking assistance with a menu issue. I have a horizontal menu with subitems that display when clicked, but having trouble with the submenu behavior. When clicking on a submenu item, I want it to remain open and show the related items underneath it. For ex ...

How to run 'npm' scripts externally in package.json on Windows?

In the world of development, running arbitrary commands using npm run is a common practice. This involves adding a scripts hash to your package.json: "scripts": { "build-js": "browserify browser/main.js | uglifyjs -mc > static/bundle.js" } To exec ...

How to resize and center an image within a div element as they both scale proportionally

Can someone help me figure out how to center a resized image within its container, which should also be centered? I've been struggling with this for 7 hours and can't seem to get it right. Any assistance would be greatly appreciated :-) Here is ...

Navigating through each element of an array individually by using the onClick function in React

I'm currently working on a project that involves creating a button to cycle through different themes when pressed. The goal is for the button to display each theme in sequence and loop back to the beginning after reaching the last one. I've imple ...

.class selector malfunctioning

I'm currently developing a card game system where players can select a card by clicking on it and then choose where to place it. However, I've encountered an issue where nothing happens when the player clicks on the target place. Here is the li ...

Material-UI Issue: Why is makeStyles not working as expected?

Encountered Error: TypeError: Object(...) is not a function 13 | import { connect } from 'react-redux'; 14 | 15 | > 16 | const useStyles = makeStyles(theme => ({ 17 | ...theme 18 | })); 19 | Code Snippet: const useStyles ...

"Customize the look of the action button in Material-UI's

Is there a way to customize the appearance of action buttons within a Dialog, DatePicker, or TimePicker by accessing the containing div? I'm looking to add padding between these buttons and potentially change the background color of the div generated ...

Using Javascript and CSS to Float DIV Elements

Recently, I've been working on a small algorithm that adds a special class to an element when the mouse reaches the halfway point or beyond on the X-axis of the browser. I also have a screenshot that demonstrates where this application will be utiliz ...

Guidelines for choosing AngularJS checkboxes to exclusively choose distinct matching items

Need help with selecting common items using Angular checkboxes. Below is the mock UI-Table: Order Id | Delivery Mode | Select 1 | Speed | ::checkbox:: 2 | Normal | ::checkbox:: 3 | Contractor | ::che ...

Flex items in the center are getting truncated when viewed on a smaller screen size

I have a group of divs in my list, here's an example: .container { display: flex; flex-direction: row; justify-content: center; } When the container is larger than the viewport upon resizing, the first/second items get clipped off. I would like ...

Utilize JavaScript destructuring to assign values to a fresh object

When working with JavaScript/Typescript code, what is a concise way to destructure an object and then assign selected properties to a new object? const data: MyData = { x: 1, y: 2, z: 3, p: 4, q: 5 } // Destructuring const { x, z, q } = data; // New O ...

What is the best way to use jQuery's get function to load multiple files at once?

I am attempting to use jQuery's get function to load multiple files. Here is a basic example of what I am trying to achieve: <!doctype html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/ ...

What could be causing the issue with my custom AlloyEditor UI extension?

After following the instructions in this guide to integrate alloyeditor as a WYSIWYG editor into Contentful, I successfully added the extension to my contentful staging space. However, despite copying the html page from the github repository and includin ...

Optimizing Style Inclusion Order with Vue SFC, vue-loader, and webpack

My Vue/SFC/webpack/vue-loader application integrates bootstrap using 'import', with component styles directly included in the SFCs. However, vue-loader always places bootstrap after the component styles, preventing proper overwrite/cascade over b ...

How can you append an object with a defined key to an array in Vue?

Currently developing a vue-application that includes a component for managing driving licenses. Here is an overview of my data setup: data() { return { custom_licenses: [], basic_licenses: [] } } Within my methods, I have the following l ...

Utilize JavaScript to iterate through a JSON object and retrieve the indices that meet the specified criteria

While I found a previous answer that somewhat addresses my issue, I am seeking guidance on how to return an array of the indexes where a specific value appears. For example, if **18A38** is the target value, it should return the positions [1,3]. The sampl ...

Update the var value based on the specific image being switched using jQuery

I have implemented a jQuery function that successfully swaps images when clicked. However, I am now looking to enhance this functionality by passing a parameter using $.get depending on the image being displayed. Here is the scenario: I have multiple comm ...

Appium with Node.js (wd) becomes unresponsive when unable to locate element

Encountering an issue while using appium with nodejs (wd) and mocha, as there is a loading view in the android app (blackbox testing & I'm not the developer) that needs to be waited for its disappearance. Attempted the following solution: wd.addPromi ...