Tips on how to automatically scroll a display flex div to the bottom

Traditionally, setting scrollTop of a div can be used to scroll it to the bottom, as shown in this example: http://jsfiddle.net/jPVAf/50/

However, if the div has the style display: flex, the technique mentioned above will not work. Here is an example demonstrating this: http://jsfiddle.net/hoch47n6/. How can JavaScript be utilized to scroll the div to the bottom in such cases? Thank you!

Answer №1

The reason behind this issue is due to the justify-content property.

To fix it, you should reset the properties of the <p> element and adjust the line-height so that jQuery can accurately determine the height of the <p> tag.

You can check out the revised version on Fiddle (jsFiddle) for more details.

Just a little tip for your reference:

/* Resetting <p> */
p {
  margin: 0;
  padding: 0;
  line-height: 50px;
}

I hope this information proves useful to you!

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

Using AngularJS and ServiceStack webservice, perform the "get('url')" operation

I'm completely new to AngularJS and I'm attempting to retrieve some JSON items from a webservice I quickly set up using ServiceStack. When I enter the URL in the browser, I can see the JSON object without any issues. However, for some reason Angu ...

A guide on how to navigate the parent window from a child window

When using my application, I have a function that opens a new window like this: window.open("www.example.com"); Within the new window, there is a button. Upon clicking this button, the new window should close and then redirect the parent window to a diff ...

Selecting a database design pattern for varying database types

After creating a class to manage interactions with my database, I realized that I need separate classes for two different modes: admin and client. class MyDatabase { connect() { /* ... */ } } So, I decided to create two new classes: class MyDatabaseAd ...

In order to check a checkbox, you need to ensure that the scrolling div has been scrolled to the very

I have a situation where I need to ensure that a user has scrolled to the bottom of a disclaimer before they can acknowledge it by checking a checkbox. Our legal department requires this extra step for compliance reasons. Here is an example of how the mark ...

Is there a way to configure eslint to recognize and allow the nullish-coalescing assignment syntax?

The "nullish-coalescing assignment" operator, ??=, has been around for some time now in JavaScript. However, it appears that even newer versions of eslint, like 8.38.0, do not seem to recognize it and throw a syntax error regarding the assignment ...

Turning a string into JSON (encountering an unexpected token u/')

One burning question remains: why is this not functioning properly? It keeps throwing an 'unexpected token' error! var inquiry = "{'form_id':'foo','title':'bar'}"; console.log(JSON.parse(inquiry)); ...

Repositioning a variable number of divs as the cursor hovers over the target area

Can anyone show me how to generate div elements in a loop using jQuery and change their position with the "mouseover" function? I've tried some code, but the positioning isn't changing correctly. Any suggestions on what needs fixing? var r, g, ...

Vue.js - Axios Get request received an object response

My current project is built on Vue.js and I am using Flask for the API. The issue arises when trying to make an axios.get request - the API returns an object 'Object'. Interestingly, when testing the same request in Postman, it works fine and ret ...

Running res.render in an asynchronous manner within an express application

My goal is to make this router respond asynchronously: var express = require('express'), router = express.Router(); router.get('/', function(req, res, next) { res.render('contact', { titleShown: true, title: & ...

How can I incorporate multiple JSX files into plain HTML without using npm?

I have a question regarding importing JSX files in an HTML file without using npm and directly running it with LiveServer. I have two files, index.js and app.jsx, that I want to connect within my index.html script. How can I achieve this? Code: index.html ...

Steps to invoking an asynchronous function within another async function

Is there a way for me to transform the following function into an Async function? I need to invoke several methods based on the result of the function call when isMaxAttemptExceeded has been fully executed. let isMaxAttemptExceeded = async () =&g ...

Challenges with inserting a new line in a textarea are posing

Hello everyone, I'm facing an issue with my textarea. It seems that even though I can input a new line in it all day long, when I submit the box, the text appears as one continuous sentence. Any suggestions on how to fix this? <tr id="commentRow"& ...

Animating path "d" with ReactJS and SVG upon clicking in FireFox

Visit this CodePen for more: https://codepen.io/sadpandas/pen/xxbpKvz const [currentScreen, setCurrentScreen] = React.useState(0); return ( <React.Fragment> <div> <svg className="theSvg" width="156" height="6 ...

The JavaScript code is failing to load

Ensuring my HTML and JavaScript code is well-organized, I have separated all the JavaScript code into different files. However, when attempting to insert the code into the HTML page, it does not function as expected: <html xmlns="http://www.w3.org/199 ...

Require assistance in accessing the second tab on a webpage using JavaScript tabs

Currently, I have a web page with two tabs that are initially hidden until the corresponding tab button is clicked. The click event is managed by jQuery. For example, let's assume that tab 1 is the default one when the page loads. Now, I am looking fo ...

Encountering problems during the installation of Ionic - Error code 'EPROTO'

After attempting to install Ionic on my system, I encountered the following error message: npm ERR! code EPROTO npm ERR! errno EPROTO npm ERR! request to https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz failed, reason: write EPROTO 0:er ...

A crisscrossing dashed design running along the edges of the text block

<div class="search"> <p>SEARCH</p> </div> https://i.sstatic.net/yxOga.png I am attempting to incorporate a dashed lateral padding similar to the one shown in the image, but only on the sides of the text. Is there a method I can ...

Regular expression for matching zero's following a decimal

I'm currently working on a regex method to validate decimals that only allow 2 numbers after the decimal point. For example, it should return true for 1.00 and false for 1.000, which it currently does. However, I also want it to return false for value ...

The issue with Angular's mat-icon not displaying SVGs masked is currently being investigated

I have a collection of .svgs that I exported from Sketch (refer to the sample below). These icons are registered in the MatIconRegistry and displayed using the mat-icon component. However, I've observed issues with icons that utilize masks in Sketch ...

Learn the steps to export a constant value in Next.js using React!

I need to export the constant value views from BlogPost.js to blog.js. This is the content of BlogPost.js: import React from 'react'; import useSWR from 'swr'; import format from 'comma-number'; import { useColorMode, He ...