Calculating the CSS `top` value for a sticky table header without the use of Javascript

Is it possible to dynamically adjust the height of a sticky table header bar in CSS, rather than using JavaScript to compute and apply the height?

While I am aware that CSS variables can fix the height at 50px, I would prefer for the height to be determined based on the content. Any suggestions on how to achieve this?

body {
  margin: 0px;
  padding: 0px;
}

#container {
  display: inline-block;
  minimum-height: 100vh;
}

#first_bar {
  position: sticky;
  left: 0px;
  width: 100vw;
  background: red;
}

#second_bar {
  position: sticky;
  top: 0px;
  left: 0px;
  height: 50px;
  width: 100vw;
  background: blue;
}

#other_content {
  background: grey;
}

#table_header {
  position: sticky;
  width: 200vw;
  top: 50px;
  background: yellow;
}

#large_table {
  width: 200vw;
  height: 200vw;
  background: green;
}
<div id="container">
  <div id="first_bar">navigation</div>
  <div id="second_bar">action bar</div>
  <div id="other_content">other content</div>
  <div id="table_header">table header</div>
  <div id="large_table">table</div>
</div>

How can I ensure that the table header remains below the action bar as the large table scrolls vertically and other content disappears?

Answer №1

I'm a bit confused about your request, but I believe you're looking to implement CSS variables

:root {
--variableName: 50px 
--colorName: #141414
}

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

Use jQuery to select and emphasize the following menu option

Hey there! I'm currently working on adding a new feature to my website. I want the menu items to highlight in succession when clicked. For example, if I click on people, I want it to highlight and then move on to highlight the next item in the menu, w ...

Retrieve Latitude and Longitude by clicking using JavaScript

When I click on the map, I want to retrieve the latitude and longitude coordinates and display them in an alert. Here is the code I have: <!DOCTYPE html> <html> <body> <div id="googleMap" style="width:100%;height:400px;"></div&g ...

Excessive blank space surrounding Bootstrap typography

Despite using margin and padding set to 0, as well as adjusting the line-height, Bootstrap 4 still leaves unnecessary space around text. This issue can make aligning elements with text quite challenging. Take a look at the red line in the screenshot below ...

Height Issue with Nested Columns in Bootstrap 5

My nested columns are giving me trouble with their height. I want them to have equal heights on both big and small screens. Currently, the sizes look perfect on the largest and smallest viewports, but not on medium-sized ones. Check out examples on codepen ...

Angular show more button determined by line count, not letter count

I am looking for a solution in Angular or CSS that will automatically add a "read more" button if the text is longer than 5 lines. My Angular page currently limits text to 150 characters. {{post.post_text | limitTo:letterLimit}} However, some posts are ...

Set iframe or form to be in a fixed position

Having issues with my site where an iframe is contained within a div. When only one character is entered in the telephone box, validation fails and red warning text is displayed. Furthermore, after clicking in the email box and pressing tab twice, the fo ...

Refreshing chosen value (html) utilizing buttons

In my code, I have a Select that allows me to choose the number of a chapter I want to display (see image): <select name="select" onchange="javascript:sliders[0].goTo(value);"> <?php for($i=1; $i<$row['nbChapitre']+1; $i++){ ?> ...

What is the best way to include an icon with dropdown menu options?

I am facing an issue with a text box and modifier dropdown. I want to display an icon representing the current choice when selected. However, using UNICODE for icons causes them not to display properly in certain browsers like Google Chrome unless specific ...

Adaptable placement of background across screen widths

I am facing an issue with three buttons that have the same height and width, text, and background icons on the right. On small screens or when there is only a single word in the button, I want to move the icons to the bottom center of the button. Is there ...

Tips for speeding up page loading when using the same image multiple times on a page

Is it possible to utilize a JavaScript Image object? If yes, could you provide an illustrative example? And is it feasible to achieve this with jQuery? ...

Limiting the size of textboxes in Twitter Bootstrap

I am currently working with bootstrap text boxes in the following manner: <div class="row"> <div class="col-lg-4"> <p> <label>Contact List</label> <select class="form-control" id="list" name="li ...

Creating an Android game with the utilization of HTML5 and Javascript involves the adaptation of images to various screen resolutions

Currently, I am working on creating a basic game for android devices by utilizing HTML5, javascript, and cordova for wrapping it up. One of the key features of my game will involve using an image as a background and animating it to create a dynamic visua ...

Having trouble implementing custom fonts in React App for all browsers

While working on my project, I included custom .woff fonts using @font-face and stored them in my src folder. Surprisingly, the fonts displayed correctly when running the app locally. However, upon deploying the app to the live domain, Chrome and Firefox ...

Error: Validation issues detected in field functionality

My goal is to loop through a set of text fields and check if the user has input any values. However, I'm facing an issue where even though I have provided values in the text fields, it seems like they are empty. To better illustrate my problem, I have ...

How can I dynamically pass a background:url using JavaScript to CSS?

I have a CSS code snippet below that I would like to dynamically change the "background:url" part using Javascript. div{ background: url('pinkFlower.jpg') no-repeat fixed; -webkit-background-size: cover; -moz-background-size: cover; ...

What is the distinction between selecting and entering a date input value?

When a user selects a date, it needs to be immediately sent to the server. If they manually type in the date, it should be sent on blur. The issue arises when the oninput event is triggered for each keydown event, causing unnecessary server requests while ...

Troubleshooting a peculiar CSS margin problem exclusively in Internet Explorer

I am currently utilizing a grid system to create a responsive layout for a single webpage on our company's official site (lexisnexis.stacklaw.com.au). However, I have encountered some CSS problems when displaying the page in Internet Explorer. The [+ ...

Code Snippet: Adjust Table Column Alignment using CSS

Apologies for the basic question, as I am new to CSS. Below is the UI that I am working with: https://i.stack.imgur.com/crAYE.png Here is the code that corresponds to the UI: <div class="row centered-form center-block"> <div cla ...

Avoid choosing the menuItem when clicking on the icon within the Material UI select component

I am trying to create a dropdown menu that allows users to delete items. However, when I click on the delete icon within a menu item, the entire menu item gets selected automatically. How can I prevent this default behavior? Here is my code: { dropd ...

Tips for identifying emails from protected platforms such as ProtonMail or Hushmail

A question for the community: So, I have a website that's totally above board and legitimate. Lately, I've noticed some shady characters trying to register from email domains like Proton and Hush - yikes! Before I dive into PhoneText validation, ...