Is it possible to utilize viewport height as a trigger for classes in Gatsby?

Unique Case

Working on a Gatsby site with Tailwind CSS has brought to light an interesting challenge regarding different types of content. While the blog pages fill the entire viewport and offer scrolling options for overflowing content, other pages with less content require manual scrolling. My goal is to have a fixed footer at the bottom of the page, similar to a slide in a presentation, with the header always remaining fixed at the top.

"Innovative Solution"

To address this issue, I devised a simple solution involving two types of footers - one fixed and one loose. By implementing a conditional tag like

<Layout footer="loose">...</Layout>
, I can easily switch between the two while coding the pages.

The Dilemma

Diving deeper into testing across various browsers, I discovered that these "slide-like" pages were sometimes getting hidden below the header due to differences in viewport size and user resolution. To visualize this problem, you can visit this link or view screenshots below:

https://i.sstatic.net/PkXtA.jpg Here, the page features a fixed footer and a single-slide appearance, but when viewed in Opera, the content goes underneath the header.

https://i.sstatic.net/Sj8xm.jpg In another test scenario, extra content was added to observe how the layout behaves with longer content and a fixed footer.

https://i.sstatic.net/HodY2.jpg Similar to the previous case, this time with a "loose footer".

Seeking a Resolution

To enhance the responsiveness of my website, I am exploring the idea of fetching the rendered height of a page and comparing it against the viewport size. This way, a class could be dynamically applied to the footer based on the page's height, ensuring better alignment. While researching solutions, I came across an intriguing article on using breakpoints without CSS, which sparked ideas for creating a hook that automatically adjusts the footer based on these metrics.

As I haven't found a concrete method to tackle this particular issue, I welcome any insights or suggestions in resolving this challenge effectively.

Answer №1

html,
body {
  margin: 0;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
}
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">

<header class="flex-initial bg-gray-700 text-gray-200 p-6">
  my header
</header>
<main class="flex-1 bg-gray-400 text-gray-800 p-6">
  <h1>HTML Ipsum Presents</h1>

  <p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt ... 

  <h2>Header Level 2</h2>

  <ol>
    <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
    <li>Aliquam tincidunt mauris eu risus.</li>
  </ol>

  <blockquote>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit... 

  <h3>Header Level 3</h3>

  <ul>
    <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
    <li>Aliquam tincidunt mauris eu risus.</li>
  </ul>

</main>
<footer class="flex-initial bg-gray-200 text-gray-700 p-6">
  my footer
</footer>

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

Create a loop in Vue.js 3 without the need for a query

Can someone help me understand how to fetch data using a loop in Vue.js version 3 when working with queries? I am trying to retrieve an object based on its id, which is obtained from the URL. However, I seem to be facing some difficulties. Any guidance wou ...

Converting lists to JSON format in a C# web form

Utilizing JSON.stringify, I have implemented textbox autocomplete for a web-form that suggests city names based on user input. The goal is to retrieve relevant city names from the database and display them as suggestions in the autocomplete feature after t ...

The appearance of the Angular material component is altered once integrated into a new Angular application compared to its presentation in the provided example

After adding the Angular Material component "Toolbar" to my project, I noticed that it does not appear the same as it does in the example provided. Despite using the same styles, the outcome is different. Here is what the example looks like on the project ...

Hover effect for child element not activating CSS3 Transition

I need my list item to activate a css3 transition on its child element .pusher when it is hovered over. I usually achieve this using JS, but I want to try implementing it with css3 transitions. After reading some other questions on SO, I attempted to do it ...

The put method is not recognizing the Axios callback function

Having an issue with Axios callback not working when updating a MySQL database. The data gets updated successfully, but the callback function doesn't work. Strangely, post, delete and get callbacks are working fine. Here is the code snippet: Frontend ...

Ways to update the content within an IFRAME using server-side methods

I've searched through many posts, but I still haven't found a clear solution to my problem. Here's what's going on: I have a page with an IFRAME that is pulling content from a different domain. The style of the frame doesn't match ...

The second jQueryUI datepicker instance flickers and vanishes when the show() function is triggered

I currently have two jQueryUI datepickers integrated into my webpage. The initialization code for both is as follows: jQuery("#departureDate").datepicker({ beforeShow: function() { getDatesForCalendar("outbound"); }, numberOfMonths: 3 ...

Trouble accessing Silverlight site due to incomplete loading

There is a site known as that consists of a Silverlight application. Strangely, this site loads on all other computers except mine. I keep encountering the following error: An Error occurred in the Silverlight Application: String was not recognized as a ...

What is the best approach to dynamically retrieve an API route from a component within the page directory?

I am encountering a problem with my reusable contact form. It functions perfectly when used in the index.js file, but when I try to use it from a component in the page folder, I receive a 404 not found error message. This is because it tries to access the ...

Tips for resolving issues with the navigation menu not appearing on the website

For more information, please visit the webpage at I am facing an issue where the dropdown menu does not show up when hovering on the Services page. The dropdown menu was created in WordPress using wp_nav_menu. There are 5 pages, including a Services page ...

Embedding a CSS file into a PHP class

I've encountered a little issue that I can't seem to solve on my own. I've put together a "webengine" using multiple classes. The primary class responsible for obtaining a theme's internals is called "Logic". This Logic class contain ...

Steps for launching a browser using Capybara and Selenium

I am completely new to utilizing Capybara and have not had any experience with Selenium in the past. Currently, I am working on a Ruby on Rails project on MacOSX and encountering an issue where the browser window does not open when I execute my test. My te ...

Troubleshooting: Issue with selecting items in jQuery Datatables

While attempting to construct a jQuery datatable using a data object, I encountered an issue. The table is displayed correctly, but the selection feature within the datatable is not functioning as intended. My expectation was that when a row is selected, i ...

"Encountering issue with jQuery $.ajax DELETE not triggering then() function

I have implemented some code within a Chrome extension that effectively utilizes the then() method from the xhr response when using $.ajax. if (request && request.action === "updateTask") { $.ajax({ type: "PUT", url: config.upda ...

What is the solution to prevent angular-material components from covering my fixed navbar?

After creating a navbar using regular CSS3, I incorporated input fields and buttons from angular material. However, my sticky navbar is being obscured by the components created with angular material. Here is the CSS for the navbar: position: sticky; top: ...

Accessing information from a database in ReactJS and passing the resulting promises to the return function via the .then method

Summary; I am currently working on integrating data from an API into my React application upon loading to ensure immediate availability. I am open to revising and restructuring the code if necessary, as long as I can achieve this functionality. It seems th ...

javascript An interactive accordion component created with Bootstrap

I have been searching for a solution to create an accordion-style collapsible set of panels where the panels remain separate and do not have headers. I want buttons on one side, and when clicked, a panel is displayed on the other side. Only one panel shoul ...

How can you simulate a 'click' event on the currently active tab of a jQuery tab?

Hey there, I'm trying to automate a tab click on my website when a form is submitted and the return is valid. Here's a snippet of the HTML code: <ul id="tabUL" class="tabs js-tabs same-height"> <li class="current"> <a ...

Discover the best method for summing all values within a JSON object that contains multiple unique keys

What is the best way to sum up all values in a JSON object? The object provided below contains values that are in string format and it has different keys. var numbers = { x: "4", y: "6", z: "2" }; The result should be: total ...

How to place a child <div> within a parent <div> that is fixed on the page

I am currently working on creating a modal window using HTML/CSS. My goal is to have the modal window fixed in position relative to the browser window, with a white background. Inside the modal, there will be an image at the top and a div element at the bo ...