Issue with sticky positioning not functioning on column headers

Is there a way to make the position sticky work with content that has the style columns? I created an example in JSFiddle to demonstrate the issue: Check it out here

.sticky {
  position: sticky;
  top: 0;
  background: #000;
  color: #FFF;
}

.content {
  height: 200px;
  background: #FFF000;
}

.min {
  width: 48%;
  vertical-align: top;
  display: inline-block;
}

.notworking {
  columns: 100px 3;
}
<div class="min">
  <div>
    <div class="sticky">Working 1</div>
    <div class="content">Content 1</div>
  </div>
  <div>
    <div class="sticky">Working 2</div>
    <div class="content">Content 2</div>
  </div>
  <div>
    <div class="sticky">Working 3</div>
    <div class="content">Content 3</div>
  </div>
</div>

<div class="min notworking">
  <div>
    <div class="sticky">Not Working 1</div>
    <div class="content">Content 1</div>
  </div>
  <div>
    <div class="sticky">Not Working 2</div>
    <div class="content">Content 2</div>
  </div>
  <div>
    <div class="sticky">Not Working 3</div>
    <div class="content">Content 2</div>
  </div>
</div>

Any solutions or workarounds for this issue?

Answer №1

Sticky positioning may not function as expected within column logic due to the fluid nature of elements within columns. Instead, consider using grid for more predictable behavior.

.sticky {
  position: sticky;
  top: 0;
  background: #000;
  color: #FFF;
}

.content {
  height: 200px;
  background: #FFF000;
}

.min {
  width: 48%;
  vertical-align: top;
  display: inline-block;
}

.notworking {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
}
<div class="min">
  <div>
    <div class="sticky">Working 1</div>
    <div class="content">Content 1</div>
  </div>
  <div>
    <div class="sticky">Working 2</div>
    <div class="content">Content 2</div>
  </div>
  <div>
    <div class="sticky">Working 3</div>
    <div class="content">Content 3</div>
  </div>
</div>

<div class="min notworking">
  <div>
    <div class="sticky">Not Working 1</div>
    <div class="content">Content 1</div>
  </div>
  <div>
    <div class="sticky">Not Working 2</div>
    <div class="content">Content 2</div>
  </div>
  <div>
    <div class="sticky">Not Working 3</div>
    <div class="content">Content 2</div>
  </div>
</div>

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

What are some efficient ways to condense a lengthy HTML list with numerous items?

After creating 22 lists with 50-100 items each, I realized that they are taking up a lot of space in my HTML code - approximately 25k lines. How can I optimize this and make them more concise? For instance: I am considering using only one item in the lis ...

What is the best way to incorporate a button following every element in a Jade iteration?

Having trouble locating a solution to this issue. It's possible that I'm not conducting the right search. My current code looks like this: each val in district_list li= val button.btn.btn-sm(type="submit") Remove With this code, a Remove b ...

Interactive canvas artwork featuring particles

Just came across this interesting demo at . Any ideas on how to draw PNG images on a canvas along with other objects? I know it's not a pressing issue, but I'm curious to learn more. ...

Footer displaying strange behavior

I am working on creating a static web page within a larger Laravel project. Everything is functioning properly except for the footer which is displaying unusually. Despite being positioned at the bottom of the HTML structure, it is taking up more space and ...

Unusual shadow cast by the box's silhouette

I am currently facing an issue with a box and its shadow. When I close the box, a different shadow lingers behind. I have tried troubleshooting this problem but cannot pinpoint the source. I have included the relevant code files in the specified folders. I ...

Tips for reducing the height of the footer without compromising the alignment of the text within

My attempt to reduce the height of my footer in CSS using padding, margin, and other methods was unsuccessful. All of these adjustments either pushed the footer completely out of the bottom or left the text uncentered. footer { background: #fce138; wid ...

Is there a way to position a child div in the upper left corner of the webpage, even surpassing its parent div?

Incorporated three columns using the bootstrap framework. Within the second column, there exists a div containing text which I aim to relocate to the top left corner of the document (rather than the parent's top left corner). Due to constraints impos ...

CSS Menu Expansion Error in Just Two Lines

My CSS-only menu is causing some trouble by expanding to three lines whenever a submenu option on the first line is clicked. The issue only occurs with options in the middle, as it shifts everything out of place and onto another line. Expected behavior: ...

Is it better to specify the image size in the height/width attributes of the img tag or in CSS settings?

What is the recommended coding practice for defining an image's size? <img src="images/academia_vs_business.png" width="740" height="382" alt="" /> Should the size be defined in the CSS style with width/height attributes instead? <img src= ...

Using Angular to showcase the names of uploaded files within an HTML document

I successfully developed an application that uses a post request to upload files to an API. Service file: onFileSelected(event){ this.selectedFile = <File>event.target.files[0]; } onUpload() { const formdata = new FormData(); formdata ...

Why is IE6 adding an additional margin of 50px? My code seems to be causing this issue

Currently I am working on creating a custom IE6 CSS. However, I am facing an issue where an extra 50px is being added to the header div. Even though I have set the header size to 109px, it is displaying at 159px. When I add any element below the header div ...

Evenly distribute top and bottom padding within a fixed-height border using CSS

I'm facing a challenge with centering the content vertically on an online certificate that users can print out. The main issue lies in aligning the inner wrapper (#wrapper) inside the outer border (#outerBorder), which has a fixed height to ensure pro ...

Minify and group options available for asset managers specifically designed for traditional HTML websites

My primary focus is on working with the CakePHP framework and utilizing a fantastic plugin that minifies and groups selected assets into a single file, reducing the number of HTTP requests needed for the entire site. Currently, I am collaborating with des ...

Looking to incorporate HTML5 videos into a responsive Bootstrap carousel?

I've been working on creating a carousel that includes videos. When it comes to images, everything works smoothly as they are responsive even in mobile view. However, I'm encountering an issue with videos where the width is responsive but the hei ...

Discover the method of using jQuery to identify a modification on a select element with an ID that is generated dynamically, and modify the choices available for selection

Our team has successfully implemented a user "profile" page with a two-column HTML table using a web framework (Rails 4.2.x). Users can dynamically add rows to this table by clicking an "add row" button, and everything is functioning as expected. The two c ...

Blank values are being submitted via the form

As I work on creating a basic form using a combination of HTML, CSS, and PHP, I've encountered an issue. While the form successfully sends an email to the designated recipient, it does not include any information entered into the form itself; only the ...

The alignment of the timeline in HTML CSS becomes distorted once it reaches the fourth element

As a newcomer to HTML, CSS, and JS, I am currently embarking on the task of creating a personal website for a course project. One of the pages on my website showcases a timeline featuring dates and information. While I have referred to a tutorial on W3scho ...

What is the process for excluding or removing an input once the PHP code has been run?

I am working on a project with a post input field where I submit simple data. <form method="post" action="result.php"> <input type="url" name="url" class="form-control" placeholder="http://example.com/"> <input type="submit" name="s ...

Change the position of the specified footer on the one-page website

I am currently in the process of creating a single-page layout website. What I want is to have the elements with the class "footer-bar" positioned absolutely on each page, but on the #Home Page, it should be position relatively. Does anyone have any sugge ...

Generate a secondary table row by utilizing the ::after pseudo-element

I need to add a sub-row to the last row of the table to achieve the look shown in the photo. I am attempting to use pseudo-classes for this purpose, but I am struggling with adjusting the height of the 'tr' element to accommodate the new content. ...