Header that stays fixed at the top within a collapsible accordion layout

I'm experimenting with creating an accordion-style layout that transitions to an accordion on smaller screens, as shown by resizing the snippet attached to this question. I'm using flex to establish a sticky header, which is currently only applied to the "Developer" label using position: sticky; however, it doesn't seem to be working as intended. I'm relatively new to flex and I'm mainly trying to utilize it for its sticky feature. I would appreciate any tips or tricks! I'm aiming to stick with just HTML/CSS for this.

.featured-table-container {
  display: flex;
  flex-direction: column;
}

.featured-table-collapse {
  cursor: pointer;
  display: block;
  background: #cdf;
}

.featured-table-collapse+input {
  display: none;
  /* hide the checkboxes */
}

.featured-sticky {
  position: sticky;
}


/*** Text/Content Style ***/

.featured-table-content {
  font-size: 20px;
  /*to fill out content so I can test sticky */
}


/*** MEDIA QUERIES ***/

@media only screen and (max-width: 760px) {
  /** Makes table collapse **/
  .featured-table-collapse+input+.featured-table-content {
    display: none;
  }
  .featured-table-collapse+input:checked+.featured-table-content {
    display: block;
  }
}
<div class="featured-table-container">
  <!-- Container that applies flex -->

  <label class="featured-table-collapse featured-sticky" for="_1">
 <!-- class = featured-sticky for position:sticky; -->
  Developer
</label>
  <input id="_1" type="checkbox">
  <div class="featured-table-content">
    Lorem Ipsum text...
  </div>

  <label class="featured-table-collapse" for="_2">
  Foundation
</label>
  <input id="_2" type="checkbox">
  <div class="featured-table-content">Content 2</div>

  <label class="featured-table-collapse" for="_3">
  Accelerator
</label>
  <input id="_3" type="checkbox">
  <div class="featured-table-content">Content 3</div>

  <label class="featured-table-collapse" for="_4">
  Enterprise
</label>
  <input id="_4" type="checkbox">
  <div class="featured-table-content">Content 4</div>

  <!-- Table container end -->
  </div

Answer №1

Utilizing the Top property will ensure it remains in place.

.featured-sticky {
  position: sticky;
  top: 0px;
}

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

Navigating Through the DOM with Selenium using XPath Axes

Currently, I am developing Selenium tests for a dynamic web page. Within this section of code, I am extracting data from an Excel sheet and verifying if a specific element exists on the webpage. I have annotated the critical part of the code with comments ...

Tips on how to add a file input type:

When working with my HTML code, I encountered an issue. When I change the type attribute to "text", everything works fine. However, when I change it to "file", nothing happens when I click. <input type="file" name="pic[]" accept="image/*">a <inpu ...

Can someone please explain how to apply various fonts to the text in a `<p>` paragraph using CSS and HTML?

Take a look at this image Can you provide guidance on how to incorporate various fonts within a paragraph, like the example shown in the image above? I am experimenting with the "Creative Corner" section. ...

Dynamic Bodymovin motion graphics

I'm trying to figure out the best way to embed a bodymovin exported file on my website so that it is responsive, maintains the correct aspect ratio of the logo and fonts, and fits within the borders of the site. Does anyone have any suggestions? Appr ...

How can I adjust the Line Opacity settings in Google Charts?

Within my Google Charts project, I have successfully implemented a feature that changes the color of a line halfway through a graph based on certain conditions using a dataView. Here is the code snippet demonstrating this functionality: var dataView = new ...

What is the best way to incorporate a massive HTML string into a WebView using the LoadHTMLString technique?

I am struggling to display an HTML string on a UIWebView using the 'LoadHTMLString' method. Below is the code snippet I am using: [wv loadHTMLString:[NSString stringWithFormat:@"<!DOCTYPE html><html><head><meta name=\" ...

What is the best way to display uploaded images on the server side in a browser using the MEAN stack?

I am currently utilizing the MEAN stack to develop an application that allows users to upload images, preview them, and save them in a MongoDB database via a server implemented with Express. Furthermore, I aim to retrieve these images from the server and d ...

Tips for updating the content of a div with fresh data using a slideshow effect in jQuery

Imagine you have a div called A and an array filled with text data. When t=0, div A will display $data[0]. Then, after every n seconds, I want the div to show the next piece of data in the array. I am interested in creating a transition effect similar to ...

Is it possible to append the .active class to a div upon clicking a button?

I'm using bootstrap's tab system to create a "set up your account" page. The steps are displayed at the top of the page above the tab-panes. When a user clicks on an option in step one, it loads the step two tab and adds the active class to the c ...

Establishing a Connection with Node/Express Routing via JavaScript

When developing a web application using HTML, JavaScript, and Node.js with Express, I often find the need to navigate between pages based on user actions. In HTML, one approach is to add an href link and then set up routes in my app.js file to handle the ...

Creating a dynamic table layout with Bootstrap

Can someone help me figure out how to make this table responsive using Twitter Bootstrap 4? Here's the JS Fiddle Link for reference. <div class="some-table-section"> <div class="container"> <table class="table some-table"> ...

Attach functions to elements added dynamically

I've been struggling with trying to attach functions to newly added elements using jQuery. Despite experimenting with various online examples, I haven't been able to get anything to work properly. My setup involves a form with an ID and a button. ...

What is the best way to integrate multiple HTML static pages within an ASP.NET MVC project while utilizing the Layout page?

I am currently working on an MVC project that requires me to include 40 static pages. I would like these pages to utilize the Layout page. What would be the most efficient method to achieve this? I have searched for answers to this question before ...

Please be aware that the website's loading speed may be slower than usual

Is it possible to notify a user that the website may take longer to load due to their slower internet connection? For example: Attention! It appears that the page is loading slowly because of your connection speed. Please be patient while the websi ...

Finding the index number of a DIV element when it is clicked

Here is an example of the HTML structure I am working with: <div id="preview-wrapper"> <div class="dz-preview dz-image-preview"> <a class="rotate-a" href="javascript:void(0);"> <img class="rotate" src="public/a ...

Is there a way to rearrange html elements using media queries?

Here is a snippet of code showcasing how my website is structured for both desktop and mobile views. Display on Desktop <body> <div> <header> <div>example</div> <a><img src"my logo is here"/& ...

I'm having trouble getting my text to center properly within a li container

I'm struggling to perfectly align the text in the middle of the li container. It seems to be centered horizontally, but vertically it's off. I've attempted adding a span to the text and adjusting the margin and padding, but so far I've ...

Activate function when list item is clicked

My goal is to execute a function when users click on the li elements in the snippet below without relying solely on onclick. For instance, clicking on the first li element (with a value of 1) should trigger a function where the value "1" is passed as an ar ...

Header image misalignment

Seeking a solution to have the image fill up the remaining space in the .container class I attempted setting the width of the image in CSS to width: 100%, but encountered two different results: Image with attribute set: https://ibb.co/9yKJgvF If I remove ...

Place centered items within a flexbox that uses space-between alignment

When designing a navigation section, I am looking to achieve space-between justification. However, for smaller screens where the navigation items may need to wrap onto multiple rows, I want the items to center themselves instead of aligning to the left whe ...