Issue with connecting Drupal 8 theme styling to website pages

Although the theme is functioning properly, the CSS styles are not being applied. Even when inspecting the developer console in Firefox, there seems to be a disconnect with the page. I verified that manually applying the CSS through the developer console in Firefox confirms that it works.

To clarify, after making changes to the theme's files, I have cleared the cache and reloaded the webpage. I have also tested different base themes but encountered the same issue. The theme is set as the default theme and appears to be operational, except for the CSS styling, as the block layout displays correctly on the page.

I suspect that the problem lies in linking the CSS to the page, despite trying various solutions such as renaming files or removing custom CSS altogether without success so far.


This is my directory structure:

- themes
  - learn
     learn.info.yml
     learn.libraries.yml
     - css
        style.css  
     - templates
        html.html.twig
        page.html.twig

Below is the code for each file:

learn.info.yml

name: learn
type: theme
Description: "A theme to learn on"
package: custom
core: 8.x
libraries:
  - 'learn/global-css'

base theme: stable
regions:
  headline: headline
  header: header
  content: content
  sidebar_top: sidebar_top
  sidebar_bottom: sidebar_bottom
  footer: Footer

learn.libraries.yml

#libraries file: learn.libraries.yml
global-css:
  css:
    theme:
      css/style.css: {}

style.css

#headline {
  grid-area: headline;
  align-self: center;
}

#topbar {
  grid-area: header;
}

#main {
  grid-area: main;
}

#sidebar-top {
  grid-area: sidebar-top;
}

#sidebar-bottom {
  grid-area: sidebar-bottom;
}

#footer {
  grid-area: footer;
}


.container {
  font-family: Georgia, sans-serif;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  grid-template-rows: auto;
  grid-template-areas:
    ". headline headline ." 
    "header header header header"
    "main main main sidebar-top"
    "main main main sidebar-bottom"
    "footer footer footer footer";

}  

page.html.twig

<div id="headline">
    {{ page.headline }}
</div>
<div id="topbar">
    {{ page.header }}
</div>
<div id="main">
    {{ page.content }}
</div>
<div id="sidebar-top">
  {{ page.sidebar_top}}
</div>
<div id="sidebar-bottom">
  {{ page.sidebar_bottom}}
</div>
<footer id="footer">
  <hr>
  {{ page.footer }}
</footer>

html.html.twig

<head>
  {{ head_title }}
</head>
<body>
  {{ page_top }}
  {{ page }}
  {{ page_bottom }}
</body

Source code for the webpage:

<script type="application/vnd.drupal-ajax" data-big-pipe-event="start"></script>

<script type="application/vnd.drupal-ajax" data-big-pipe-event="stop"></script>
</body><head>

</head>
<body>
  <div id="toolbar-administration" role="group" aria-label="Site administration toolbar" class="toolbar">
  <nav id="toolbar-bar" role="navigation" aria-label="Toolbar items" class="toolbar-bar clearfix">
    <h2 class="visually-hidden">Toolbar items</h2>
                ... (This part has been shortened for clarity)
</body>

Apologies for the lengthy explanation, but I wanted to cover all the details thoroughly.

EDIT:

While the solution is correct, I want to emphasize that

<css-placeholder token="{{ placeholder_token|raw }}">

is the crucial line that resolved the CSS linking issue.

Answer №1

There seems to be a discrepancy in your libraries.yml file with the file names.

The current entry is for css/custom.css: {}, but the actual file name is style.css.

To resolve this, update the entry from css/custom.css: {} to css/style.css: {} in your "learn.libraries.yml" file.

EDIT:

Additionally, make sure to include {{ page_top }} and {{ page_bottom }} in your html.html.twig file as they contain important elements like script tags.

For example:

<body>
<head>
</head>
{{ page_top }}
<div id="page" class="container">
  {{ page }}
</div>
{{ page_bottom }}
</body>

Furthermore, consider moving the

<div id="page" class="container">
to the page template.

EDIT 2.

If you are using the "stable" theme as your base theme, it might be helpful to copy its template and modify it accordingly to troubleshoot the issue.

Upon reviewing the "stable" theme's html.html.twig provided below, it appears that there are some missing components that could potentially be causing the problem.

Notably, pay attention to the css-placeholder tags which seem crucial based on your situation.

This is how the stable theme's html.html.twig looks:

<!DOCTYPE html>
<html{{ html_attributes }}>
  <head>
    <head-placeholder token="{{ placeholder_token|raw }}">
    <title>{{ head_title|safe_join(' | ') }}</title>
    <css-placeholder token="{{ placeholder_token|raw }}">
    <js-placeholder token="{{ placeholder_token|raw }}">
  </head>
  <body{{ attributes }}>
    <a href="#main-content" class="visually-hidden focusable">
      {{ 'Skip to main content'|t }}
    </a>
    {{ page_top }}
    {{ page }}
    {{ page_bottom }}
    <js-bottom-placeholder token="{{ placeholder_token|raw }}">
  </body>
</html>

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

Tips for adjusting column positions in a table while maintaining a fixed header and utilizing both horizontal and vertical scrolling

Is there a way to display a table that scrolls both horizontally and vertically, with the header moving horizontally but not vertically while the body moves in both directions? I have been able to shift the position of the columns, however, I am struggling ...

uncovering the precise text match with the help of Beautifulsoup

I am looking to retrieve the precise matching value of text from HTML using Beautiful Soup. However, I am encountering some similar text along with my desired exact match. Here is my code: from bs4 import BeautifulSoup import urllib2enter code here url="h ...

What are the steps to achieve a smooth transition from a background-image to transparency?

Take a look at this related image: The goal is to replicate the design shown on the right side of the image. However, there's also a parent container with its own background image, as opposed to a solid color. Any guidance on how to achieve this? U ...

Is it possible to modify the flex direction in Bootstrap based on specific breakpoints?

I am currently utilizing Bootstrap 4 for my project. I have a div that is styled with "d-flex" and it is meant to display as a row at the "lg" breakpoint (screens 1200px and above). However, on smaller devices such as mobile phones at the "sm" or "xs" brea ...

Ensure there is a blank space preceding a table only when the table is being physically printed

I am currently in the process of developing a report card system for students in grades K-6. The report card will display specific tables based on the student's grade level. For example, a 5th grader may not have a "Reading Stage" table displayed on t ...

Embed a div opening tag within a jQuery function for one element, and then add a closing div tag after another element

Struggling with examples from the jquery documentation, I find it difficult to add a div before a specific list item and then close it after another using different classes for each li element. The prependTo and append functions don't seem to work as ...

Wordpress easily adjusts post alignments for a seamless display

Can anyone help me figure out how to properly align posts in Wordpress to match the example image attached? I've tried using inline-block or float with CSS/HTML, but the posts are not aligning correctly. I'm unsure of what this method is called s ...

Modifying a single element within a class with Jquery

Is it possible to create a stack of pages on a website using JQuery? I found this image that shows what I'm trying to achieve: image. Instead of applying ID css for each page, I'd like to use JQuery. While researching similar questions, I came ac ...

Images for the background of the table header and sorting icons

Currently, I am utilizing jquery.tablesorter for table sorting functionality. However, I have a desire to apply a pattern to my table headers using a background-image. Unfortunately, when I do so, the .headerSortUp and .headerSortDown classes on the sorted ...

Is it possible to target a specific element within one of two classes that share the same name using CSS or XPath in Webdriver.IO?

Currently, I am using Webdriver.io and facing a challenge in selecting an element within the "text-fields-container" class. This particular element happens to be a password field, and both classes share the same name. Can someone guide me on how to go abou ...

Clicking on tabs causes their content to mysteriously vanish

I am working on creating a dynamic menu using jQuery that switches content based on tabs. However, I am facing an issue where clicking on a different <li> item causes the content to disappear. Each list item should correspond to different content sec ...

Utilizing cheerio to set outerHTML in HTML

Could someone kindly assist me with setting the outerHTML of an element using cheerio? I seem to be encountering some issues with this process. For example, let's consider the following HTML structure: <div class="page-info"> <s ...

Experimenting with combining a CSS class alongside the Nth-child selector

Hello, I've been researching various sources including Stackoverflow on how to effectively use an Nth child selector and a Class together but have not had much success so far. In essence, my menu consists of Main categories (class = cat) and subcateg ...

Ways to display JSON in a structured format on an HTML page

Is there a way to display JSON in a formatted view on my html page? The JSON data is coming from a database and I want it to be displayed neatly like the following example: { "crews": [{ "items": [ { "year" : "2013", "boat" ...

Revise Swagger UI within toggle button switch

My project aims to showcase three distinct OpenApi definitions within a web application, enabling users to explore different API documentation. The concept involves implementing a toggle button group with three buttons at the top and the Swagger UI display ...

Are you experiencing issues with Font Awesome Fonts failing to load?

I am currently using a rails app with bower to manage my assets, avoiding gems for JS and CSS. In the directory vender/assets/stylesheets, I have "font-awesome" containing both scss and fonts. In app/assets/stylesheets/application.scss, I have included va ...

Animation using jQuery is functional on most browsers, however, it seems to

After creating an animation to simulate an opening door using jQuery, I discovered that it works perfectly on Firefox 24, Chrome 28, and IE 8. However, Safari presents a problem - the door opens but then the "closed" door reappears at the end of the animat ...

Once the page is refreshed, the checkbox should remain in its current state and

I have a challenge with disabling all checkboxes on my page using Angular-Js and JQuery. After clicking on a checkbox, I want to disable all checkboxes but preserve their state after reloading the page. Here is an example of the code snippet: $('# ...

"I am looking for a way to retrieve dynamic data from a (click) event in Angular. Can

Within my component, I have a video loaded in an i tag on a click event. The challenge is accessing the video ID from the video.component.ts file in order to dynamically load a new video. The solution has been elusive so far. <li *ngFor="let video of c ...

Guide on converting HTML datetime picker datetime-local to moment format

I am looking to convert an input type : <input type="datetime-local" name="sdTime" id="stTimeID" onChange={this.stDateTime} /> into a specific date format: const dateFormat = 'MM/DD/YYYY hh:mm:ss a'; To achieve this, I need to transfer ...