~/drupal/bootstrap-sticky-is-not-sticky-drupal.md

Drupal 8: Bootstrap Sticky is not sticky in Drupal 8 - Solved

1 min readAugust 05, 2018by Gorav Singal#bootstrap-sticky#drupal-8#drupal
// TL;DR

Drupal 8 adds extra wrapper divs that break Bootstrap sticky positioning; fix it by adding overflow-y:auto to the parent region div.

Drupal 8: Bootstrap Sticky is not sticky in Drupal 8 - Solved

Bootstrap has a simple solution to have sticky blocks in your html. I’ve given a simple example in my previous post: How to make sidebar as Sticky

It works like a charm. But, things get little frustrated when it doesn’t work in drupal 8.

I have 2 column theme in bootstrap 4, and wanted to use a block as sticky in right sidebar. I made the changes, and expected it to be sticky. However, it didn’t. I spent lot of time in digging the root cause of it.

How I debug sticky problem

By some brute force, I found that drupal is adding an extra DIV, before my sidebar with code like:

<div class="region region-sidebar-first">;
...
</div>

Due to this, sticky behavior was not being set somehow.

Then, my next objjective was to remove this div.

I enabled debug: True in services.yml, and saw that it was coming from a layout/region.html.twig

I copied that file to my theme folder, see before and after code:

<script src="https://gist.github.com/goravsingal/461a6e42485a8dd04d5636a79579df89.js"></script>

Finally Issue is solved

I saved the file, cleared cache. And, voila. It worked.

Share

Related Posts

Drupal 8 - How to Theme Form and its Fields with reordering fields

Drupal 8 - How to Theme Form and its Fields with reordering fields

Introduction In this post, we will see how to theme form and its fields…

Drupal 8 - How to create a Page with admin access and create its menu entry in Reports (No Coding)

Drupal 8 - How to create a Page with admin access and create its menu entry in Reports (No Coding)

Introduction I needed a report page, where I wanted to have some information…

Drupal: How to detect country and redirect to country specific website by using Cloudflare

Drupal: How to detect country and redirect to country specific website by using Cloudflare

Introduction Assume you have a drupal website and using cloudflare. You are…

Drupal - How to rename column of a content type

Drupal - How to rename column of a content type

Introduction You already have a content type with one or more fields in it…

Drupal 8 - How to hide help link About text formats and text format guidelines

Drupal 8 - How to hide help link About text formats and text format guidelines

Problem In drupal textarea field, it was always a pain to see the two links…

Drupal 8 Smart Image Style - Handle aspect ratio for small and long images

Drupal 8 Smart Image Style - Handle aspect ratio for small and long images

Problem Statement I’ve been using image styles, and heavily used “Scale and crop…

Latest Posts

How to Stay Valuable as a Software Engineer in the AI Era: A Practical Playbook

How to Stay Valuable as a Software Engineer in the AI Era: A Practical Playbook

In the previous article I argued that AI is not killing software engineering…

How to Review AI-Generated Code: A Checklist for Catching What the Model Missed

How to Review AI-Generated Code: A Checklist for Catching What the Model Missed

A few months back I approved a PR that was almost entirely AI-generated. It…

How to Debug AI-Generated Code: Understand First, Fix Last

How to Debug AI-Generated Code: Understand First, Fix Last

In the last article I wrote about reviewing AI code before it goes in. This one…

The Future of Software Engineering: What AI Changes, What Stays, and Where the Jobs Go

The Future of Software Engineering: What AI Changes, What Stays, and Where the Jobs Go

Every few weeks somebody sends me a scary headline — “AI will replace all…

The Transactional Outbox Pattern: Never Lose an Event Again

The Transactional Outbox Pattern: Never Lose an Event Again

This is one of those patterns that looks like nothing until you get burnt once…

Event Sourcing, Explained: Store What Happened, Not Just the Final State

Event Sourcing, Explained: Store What Happened, Not Just the Final State

Here is a question I like to ask in interviews: your bank account shows a…