Tips for showcasing elements within a container while allowing users to scroll through them

I've been attempting to code a Figma design where the element starts at the middle of the screen height. As the user scrolls, the elements move upwards and stay visible until they are out of view, like in the example below.

https://i.sstatic.net/imEbD.gif

So far, I have only managed to achieve standard scrolling behavior where any overflow beyond the container is hidden

<div class="box">
   This box has specified dimensions for its height and width. If too much content exceeds 
   the assigned height, it will lead to an overflow situation. Setting overflow to 
   hidden ensures that any overflow content is not visible.
</div>
.box {
  margin-top: 50vh; /* or top: 50vh; */
  width: 200px;
  height: 100px;
  overflow: scroll;
}

Do you think it's feasible to implement this?

Answer №1

It appears that you are looking to add padding to the top using a certain number of vh units.

For more information, you can visit this link: https://css-tricks.com/fun-viewport-units/

Here is an example:

html,
body {
  margin: 0;
}

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  height: 100vh;
}

.scroller {
  padding-top: 50vh;
  height: 100vh;
  overflow: auto;
  box-sizing: border-box;
}
<div class="container">

  <div class="scroller">
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Reiciendis molestiae optio ipsam autem porro debitis, nihil expedita est quo dolor, dolore, veritatis similique. Porro id deleniti incidunt vitae, est libero.</p>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Reiciendis molestiae... (truncated)
    
</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

Angular - Dividing Functionality into Multiple Modules

I am currently working with two separate modules that have completely different designs. To integrate these modules, I decided to create a new module called "accounts". However, when I include the line import { AppComponent as Account_AppComponent} from &a ...

Is it necessary for me to use bindActionCreators?

While going through a post, I couldn't help but notice that the bindActionCreators method from redux wasn't being utilized. Is there a specific reason for this? Could it be that the method is not necessary in this context? The post in question ...

Fade in elements as you scroll using Jquery

I'm currently working on a timeline feature for my website, and I want each element with the class '.event' to fade in as the user scrolls through the timeline. However, I'm running into an issue where all elements fade in simultaneousl ...

Responsive design for off-canvas layouts

I am seeking a functional and user-friendly demonstration of off-canvas responsive design. My goal is to mirror the layout of the Google+ android app, specifically by incorporating a side panel on the right-hand side. Something similar to this particular ...

The `Meteor.depends()` function

I'm currently working my way through the Distinctive Meteor manual and I've hit a roadblock with the illustration found on page 137 var _currentLikeCount = 0; var _currentLikeCountListeners = new Deps.Dependency(); currentLikeCount = function( ...

Save data in a function

I have a functionality in place that processes data received from a server through websocket. Depending on the specific page being accessed, the data is handled differently. sock.onmessage = function (e) { log(e.data); } function returnCurrentPage(m) ...

Consistent value displayed by addEventListener for each event

Hey everyone, I've been experimenting with different solutions for a few hours now but I'm still stuck on this problem. I have a function that takes JSON as input - I can create an 'a' element: CHECK I can set all the element propertie ...

Encountered an error: $(...).DataTable is not recognized when attempting to call three separate tables on the same page with auto refresh enabled

Hello, I am new to using scripts and I am attempting to load three different tables onto my webpage, all populated from a MySQL database. Additionally, I want all three tables to automatically refresh when new data is inserted or changed. I have successful ...

Is it possible that the document is corrupted since it is not updating and no error is being displayed?

I am encountering an issue where one specific document does not update, although the same query successfully updates any other _id that I query: Category.findOneAndUpdate( {_id : req.params.id}, {parent : req.body.parent}, function(err,obj){ ...

The sudden sight of an image stretching off the page to the right

I have created a simple view with an image on the right and some text on the left. Here is how it appears: return ( <View style={styles.companyContainerStyle}> <View> <Text>{this.props.companyNameAr}</Text> ...

Updating serialized $_POST array with new key/value pair using jQuery AJAX

Is there a way to insert additional values into a serialized $_POST array before sending an AJAX request using jQuery? Here's the situation: $('#ajax-preview').on('click', function(e) { e.preventDefault(); var formData = ...

Creating a fresh React component within a current project: What steps can I take to view it on the browser?

My React project is quite complex, built using create-react-app and utilizing react-scripts to run the development server. I am looking to develop a new React component that will allow users to input structured data, complete with list additions, dropdown ...

Enhancing Angular select functionality by incorporating HTML entities using ng-option

My query is somewhat linked to this specific response, although with a slight variation. What I am aiming to accomplish is the parsing of HTML entities from a string passed onto a select using ng-options. Consider the following dataset: $scope.myOptions ...

Choose between using Paypal or Google Checkout for your shopping cart - unfortunately, both options cannot be used

My dilemma is that I currently have a functional shopping cart that is only coded for either Paypal or Google Checkout, not both. Here is a demo of the shopping cart set up for Paypal checkout: The javascript code used in the demo can be found here: Loo ...

Modifying JavaScript using JavaScript

I'm looking for a solution to change the URL of a button in sync with the iframe displayed on the screen using JavaScript. The challenge I'm facing is figuring out how to dynamically update the button's URL based on the iframe content. Here ...

Creating an array in TypeScript and determining its type as an object

Currently, I am in the process of creating an app with Ionic, utilizing TypeScript as the primary language. When declaring an array in my code: products = new Array(); I expect it to be recognized as an array. However, when I check the type using consol ...

Issues with aligning Bootstrap columns

I'm currently in the process of developing a website that interfaces with the Twitch API to display which users, from a predetermined group of 7, are online and offline. The functionality is mostly there, but I'm facing an issue where the top div ...

Error messages cannot be custom in production when reading a 409 response JSON from the server

After setting up my asp.net core MVC server, I decided to implement better error handling. However, upon deploying the changes to the production environment, I noticed a discrepancy in how my server responds to 4xx errors. While everything works fine on m ...

Using jQuery to disable a checkbox when its value matches any elements within an array

I am attempting to programmatically disable checkboxes upon page load based on certain conditions, specifically when the checkbox values correspond to records in my database. After researching solutions such as this one and here, I noticed that the main d ...

Searching for an element using Python's Selenium and JavaScript

on this page I am trying to click on the "Choose file" button but I keep getting the error message: javascript error: argument is not defined var1 = sys.argv[1] path = os.path.abspath(var1) driver.get("https://www.virustotal.com/gui/home/upload& ...