Pug conditional elements not styling with CSS

Currently immersed in the world of Pug, node.js, and express as I build a web application.

Facing hurdles when trying to style elements within Pug conditionals using CSS.

For instance, consider this Pug snippet:

div(id='outside')
  if authorised
    h3(id='unauthorised') Sorry, you are unauthorised
  else
    h3(id='authorised') Welcome!

Accompanied by the following CSS:

#outside {
  width: 100px;
  height: 10px;
  background-color: red;
}

#unauthorised {
  color: red;
}

#authorised {
  color: green;
}

The div with ID outside adheres to the CSS styles, but h3#auhtorised and h3#unauthorized don't. Similar issues persist with other selected elements.

My attempts to address this problem via the Pug Github page or research have proven futile. Any insights into what could be going wrong?


UPDATE:

To clarify, here's the actual code structure I am dealing with:

header.pug

doctype html
html
  head
    title= title
    script(src='js/action-button.js')
    script(src='js/form.js')
    script(src='https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.4/Chart.bundle.min.js')
    style
      include ../../public/css/main.css

  body
    div#test

    if isAdmin
      div(id='action-items' onmouseover='expandHoverAsAdmin()' onmouseout='closeHoverAsAdmin()')
        button(type='button' class='admin-button action' onclick='openForm();') Add role
        button(type='button' class='admin-button action' onclick='openForm();') Add user
        button(type='button' id='action-button' class='action' onclick='openForm();') +
    else
      button(type='button' id='action-button' class='' onclick='openForm();' onmouseover='expandHover()' onmouseout='closeHover()') +

main.css

div#test {
  width: 100px;
  height: 20px;
  background-color: red;
}

div#action-items {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  bottom: 20px;
  right: 20px;
  z-index: 1;
  position: fixed;
}

.action {
  border-width: 0;
  position: fixed;
  display: flex;
  justify-content: center;
  align-items: center;
  bottom: 20px;
  right: 20px;
  z-index: 1;
  width: 115px;
  height: 55px;
  border-radius: 30px; /* make circular maybe? */
  background-color: rgba(255,0,0,0.5);
  color: white;
  box-shadow: rgba(2,2,2,0.5) 2px 2px 2px 0px;
}

button:focus {
  outline: none;
}

button:hover {
  cursor: pointer;
}

UPDATE #2:

Realized that the issue wasn't due to CSS failing to apply to conditional elements but rather some changes not reflecting in my CSS file.

Revisited the above test where it previously worked fine. However, upon inspecting my local main.css file, discrepancies were noted:

#one-element {
  /* some styling */
}

#outside {
  width: 100px;
  height: 10px;
  background-color: red;
}

#unauthorised {
  color: red;
}

#authorised {
  color: green;
}

#some-other-element {
  /* some styling */
}

Whereas in Chrome Dev Tools view:

#one-element {
  /* some styling */
}

#some-other-element {
  /* some styling */
}

Edit my files with Atom and ensure regular saving, yet the missing CSS data persists. Any ideas why?

Answer №1

Resolved. I realized that the file I was updating had the same name as another one in a different directory that my pug wasn't referencing.

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

Vanilla JS causing event to fire repeatedly

My code is written in Vanilla JS and I've encountered an issue with dynamically generated content. Each click on the dynamic content returns a different value than expected: First click: 1 Second click: 3 Third click: 6 Fourth click: 10 But it sh ...

Experiencing issues with references while trying to import tone.js

I am facing an issue with my express.js server setup on my Mac. I am trying to incorporate Tone.js, which can be found at , following the provided instructions. npm install tone To integrate Tone.js successfully: import * as Tone from 'tone' Ho ...

Variances in the order of HTML elements within an article's layout

Check out this example of HTML and CSS <!DOCTYPE html> <html> <head> <title>Floats Example</title> <style type="text/css"> .left { float:left; width:100px; } .righ ...

Angular table elements can trigger a click event that redirects to a unique URL generated from the ID of the selected element

In the angular table, every element should be clickable. When any element in the table is clicked, it should use its ID to perform a new search and redirect to the URL based on that ID of the clicked element. Below is the JSON data from the initial URL. It ...

Looking to halt navigation in a Chrome browser immediately after performing a click action with Selenium?

Is there a way to prevent the browser from loading immediately after a click event? Are there any workarounds or JavaScript implementations for achieving this? ...

The error message regarding pdf.worker.min is stating that the use of 'import' and 'export' is limited to within module code and cannot be used outside of it

Upon attempting to deploy a build to Vercel, I encountered the following error message: Failed to compile. static/media/pdf.worker.min.50acc843.mjs from Terser x 'import', and 'export' cannot be used outside of module code ,-[18:1 ...

Is it possible for me to design a unique path without relying on redux?

I am working on a Loginscreen.js component import React, { Component } from 'react'; import Login from './Login'; class Loginscreen extends Component { constructor(props){ super(props); this.state={ username:'&apo ...

Is there a way to adjust the width of my web layout without sacrificing its responsiveness?

Struggling with my website layout design as I encountered an issue. The overall width of the layout is too excessive, and I want to introduce some margins on the sides for a better visual appeal. Although the responsive design works well originally, adding ...

The JQuery .ajax() function is not functioning properly, although the success method is still executing

Having issues with an ajax call on a webpage. The WebMethod is working fine. Potential problem - ajax method called from UserControl embedded in a content page within a master page, accessible only after .Net authentication. Including this info for transp ...

setTimeout is only effective for durations less than 1000 milliseconds

I am trying to implement a timeout function that displays an alert two seconds after a form is submitted. The code I have tried using does not seem to be working as expected: $(document).ready(function() { $("#newsletter").submit(function() { setTi ...

The v-html command displays unprocessed HTML code on the webpage

This is a visual representation of my component: <template> <div v-html="someHtml"></div> </template> <script> export default { name: "test", props: { someHtml: String, }, } </script&g ...

Issue with Knockout.js: Parsing error in bindings - SyntaxError: Unexpected token `};`

Take a look at this example. I've tried to simplify it as much as possible, but I'm still struggling to figure out where I went wrong. Any help would be greatly appreciated )) P.S Stack Overflow requires code, not just a link to jsfiddle. H ...

WebPack bundling causing issues with Knockout Validation

I am developing a web application using Knockout along with the Knockout-Validation plugin, and I want to utilize WebPack for bundling. However, I encountered an issue where Knockout-Validation seems to break when incorporated with WebPack. To illustrate ...

Turn off ion-slide when the application starts

Is there a way to prevent the slide feature from activating upon startup while still allowing me to set my own active page? I've discovered this helpful snippet in HTML <ion-slide-box active-page="disableSlide()"> <ion-slide>Slide 1& ...

What steps can I take to resolve the problem of my NativeScript app not running on android?

When I entered "tns run android" in the terminal, the default emulator API23 launched but my app didn't install. Instead, an error occurred. This is different from when I run it on the IOS simulator, which runs smoothly without any errors. The nati ...

Keep track of the toggled state and prevent any flickering when the page is reloaded, all without the

After extensive searching, I couldn't find exactly what I needed. Therefore, I decided to utilize cookies to remember the toggled state of a div whether it's hidden or visible. However, I encountered an issue where there is flicker happening as t ...

Positioning Avatar component at the center of Card component

Hello there, I am currently trying to center my <Avatar> elements using Material UI with React within the <Card> components. The layout appears very crowded right now. What would be the most effective method to achieve this? I attempted setti ...

Editing HTML on an ASPX website can be a breeze with

Hello there, I've been tasked with editing a website for a client, but the site is located on a local web server and was designed using aspx. As I review all the files, I am encountering difficulty finding the HTML code associated with runat=server w ...

What is preventing me from iterating through a dictionary or an array of keys?

After trying to log the dictionary using console.log(JSON.stringify(this.idTitleDict)) as suggested by @Kobe, I noticed that it was showing empty curly braces. All the code related to this dictionary (including its declaration and population) can be found ...

Incorporating a specific time to a JavaScript date object

In my Angular application, I am facing an issue with adding a time to a date. The appointmentDate from the date picker returns a JavaScript date while the appointmentTime is selected from a dropdown with options like "8:00", "8:30", "9:00", etc. I'm ...