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

I am trying to confirm in PHP whether any of the gender checkboxes have been selected. However, the code I have tried so far does not appear to be functioning as expected

Please refrain from suggesting the use of checked = "checked" in HTML, as the validation must be performed in PHP as per the requirements of my assignment. PHP Code: if (isset($_POST["gender"])) { $gender = $_POST["gender"]; if (($gender != "male") || ( ...

What is the method for changing the color of a specific section of a header?

My header design consists of two lists of buttons, one on the left and one on the right. I am looking to customize the background color of the "Sign Up" button to make it stand out. Below is an example of what I want and the current design of my header alo ...

The attempt to unserializing the configuration schema in Yii2 was unsuccessful

My brain feels scrambled... I am attempting to insert an image in HTML within Yii2. I retrieve it from the database and place it into the view file, but when I try to display it using HTML tags, an error is thrown. However, the image is being added perf ...

Customizing checkboxes in React with JSS: A step-by-step guide

I'm currently working on customizing CSS using JSS as my styling solution, which is proving to be a bit complex while following the w3schools tutorial. https://www.w3schools.com/howto/howto_css_custom_checkbox.asp HTML: <label class="container"& ...

Switching the typeface within the content data

Recently, I incorporated this code: <div data-content="Reach" class="main-image"> along with the following CSS styling: .main-image:before { content: attr(data-content); I am now wondering if there is a method to adjust the font size and ...

Create a stylish design with Bootstrap 3.0 featuring a full-width color background and compact columns perfectly centered on the

As I ventured into creating a business theme with stripes, akin to the one developed by W3Schools and accessible here, I encountered a particular challenge. The layout consisted of horizontal sections with varying background colors. My main concern was th ...

What is the method to prevent the Submit Button from being active in CSS specifically on Firefox?

When I click this CSS in webpages on Chrome (OS: Windows), it works fine. However, Firefox (OS: CentOS7) does not seem to apply this CSS on webpages. How can I resolve this issue? Should I make adjustments in the CSS code below? #submit .btn.btn-primary ...

Utilizing jQuery to apply a class to a targeted element when clicked

I'm currently working on animating a menu item where it expands to the left when hovered over, and contracts back when the mouse moves out. This part is functioning as expected. Additionally, I am trying to apply a specific color to the button by add ...

Place an image on top of adsense

Is there a way to overlay an image on top of Google AdSense ads in order to track user clicks? I am trying to implement an onclick method for when someone clicks on the ads. .ad-alert { width: 728px; height: 400px; background: #cccccc; mar ...

Keep duplicating a single object until it fills up the entire screen

Is there a way to make an HTML/CSS element repeat until it covers the entire screen height, without repeating it indefinitely? #container{ height: 100vh; width: 100vw; } .dotts{ background-color: yellow; border-radius: 50%; height: 20px; width: 20p ...

The most effective method for dynamically loading a view in Drupal 8 using contextual filters

Within my website, I have implemented a taxonomy system called "category." To navigate through these taxonomy items, I have created a menu with links to each category. Each Taxonomy page not only displays this menu but also includes a view that filters c ...

Interactive feature allowing all embedded YouTube videos on a webpage to play synchronously, with sound disabled, and on a continuous loop

I am in the process of developing a button that, when clicked by a user, will trigger all embedded YouTube videos on a specific webpage to start playing simultaneously, with sound muted, and set to loop. The target page for this button implementation can ...

Tips for incorporating the numerous values of a one-to-many relationship into an HTML template using Django

I am facing an issue with a one-to-many relationship in my Django project. Here is how it is structured: class Listing(models.Model): title = models.CharField(max_length=60) class Images(models.Model): listing = models.ForeignKey(Listing, on_delet ...

sequentially animating elements using animate css in a choreographed manner

I have created a unique jsfiddle with 20 boxes that I am trying to animate using the Animate.css plugin. The plugin can be found at daneden.me/animate. My goal is to animate each box one after the other in a sequential manner, but I seem to be having trou ...

The jQuery UI Sortable functions are being triggered at lightning speed

I am currently working on a project where users can create a seating chart, add rows and tables, and move the tables between different rows. The functionality for adding rows and moving tables already exists in the code. However, I am facing an issue where ...

Attempting to create a single function that can be utilized with numerous divs that share the same class in jQuery

Currently, I am working on creating a basic jquery gallery viewer. In my code, I have the following structure: <div class="photoset"> <img /> <img /> </div> <div class="photoset"> <img /> <img /> <i ...

The CSS background image is not functioning

.menubar li { float: left; width: 115px; text-align: center; background-image: url(js/left_main_bg_image.gif); } Having issues with the background image not displaying properly in IE, Firefox, and Chrome. I've tried adding it to a tab ...

Tips on sending the total value of a form to a PHP script

Looking for help with a PHP script to calculate the sum of checked checkboxes with corresponding numeric values. For example, if checkbox 1 = 80; checkbox 2 = 21; and checkbox 3 = 15, and the user checks checkboxes 2 and 3, the PHP should output 36. I hav ...

The variable in the HTML input value is not fully visible when filling out the HTML form

I am working with a Python Flask code where I have passed a dictionary to an HTML form. The table in the form correctly displays both keys and values, but when trying to populate a form field with the value from the dictionary, only the first word is displ ...

What is the best way to dynamically resize a div as the page size changes?

I am currently working on a project that involves a div dynamically shrinking as the page size decreases. However, I have encountered an issue where the height of the div remains constant despite this resizing: CSS .container { min-height: 180px; max ...