Tips for implementing a sticky sidebar in HTML5 with jQuery

I currently have two files: index.php and aside.php.

I've already created the contents of aside.php. Now, I want to make the aside page sticky.

To achieve this, I referred to the following link: http://codepen.io/pouretrebelle/pen/yvcBz

My struggle lies in determining the exact location for adding jQuery and CSS, and how to incorporate them into my existing code.

Can anyone provide assistance? Thank you in advance.

aside.php:


<?php
?>
<aside class="sidebar">
<div class="inside">
<section id="content">
        <!--Start Login Form --> 
        <form action="">
            <h1>Login Form</h1>
            <div>
                <input type="text" placeholder="Username" required="" id="username" />
            </div>
            <div>
                <input type="password" placeholder="Password" required="" id="password" />
            </div>
            <div>
                <input type="submit" value="Log in" />
            </div>
        </form>
                <!-- End form -->
</section>
        </div>
            <!-- Youtube palyer-1 -->
    <div class="inside">
    <section class="content">
    <video id="example_video_1" class="video-js vjs-default-skin" controls preload="none" width="315" height=
...

CSS:

/* aside */
aside {
float: left;
margin-top:320px;
padding-top:5px;
height: 200px;
position: absolute;
}
.inside {
color:#fff;
position:relative;
margin-top:10px;
}

Answer №1

If you're looking to keep a section on your website sticky without using JavaScript, you can achieve this with just CSS. Simply apply the position:fixed property to the div you want to stick, such as an aside.

Check out this example for reference: jsfiddle.net/nrmgkdne

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

Creating an Array in AngularJS with ng-model and submitting it with jQuery: A comprehensive guide

I am struggling to submit an array of values using jQuery and AngularJS. Whenever I click the submit button, only the first array value is being retrieved. How can I get all array values using ng-model? Here is a link to all my code: https://jsfiddle.net/r ...

Creating a versatile function for rendering content

I am working on a unique calendar feature that involves using checkboxes for filtering purposes. So far, I have managed to get all the filters functioning correctly by triggering my render event in this manner: //Initiate render event when checkbox is cli ...

How can I set a limit for the number of matches in jQuery :

$("div:contains(' 1434')").parent().addClass('date'); Instead of adding the class to ALL divs, I need to limit it to just the element that contains the specific text directly. While using class/id selectors would be helpful, the HTML s ...

Malfunctioning navigation buttons in the owlCarousel slider

I am using the Owl Carousel slider from . However, when I click the next button four times, it shows me the fourth element in the slider instead of moving to the next slide. The navigation buttons and dots on the carousel do not seem to work correctly. ...

Ways to extract variables from a component and utilize them in App.js

Despite my efforts to search online, I could not find the answer or understand what I needed to. My issue: I need the "inputVal" variable from the "InputField.js" component to be accessible in the "App.js" component (specifically in the fetch request where ...

Is there a way to provide "only responsive" content to the mobile m. subdomain without the need for redirection?

I currently have a website with www. that redirects to different content on the mobile m. site. I am in the process of updating my site to be responsive, but I want to ensure that I do not lose the links to the m. site in Google SERP. How can I redirect m ...

Alignment of images at the center within a container div while maintaining a height of 100%

Apologies if this question has already been addressed - I have tried numerous methods to center images horizontally without success. This particular image just does not want to align in the center! For reference, here is the JSFiddle link HTML: (Please n ...

Having trouble passing a value to a function using jQuery?

I'm facing a challenge with sending data to a function upon changing the default value of an input field. function updatePosition(currentPos, newPos) { $.post(iloc, {a:"change_pos", position:currentPos, new_pos:newPos}, function(data){ wi ...

Prevent the row height from fluctuating following the fadeOut() effect

Currently, I am facing an issue with two elements on my page: .start_over_button and .speed_buttons. In CSS, the .start_over_button is set to display: none, and in my JavaScript code, I have it so that when .speed_buttons are clicked, they fade out and the ...

The issue with the jQuery function lies in its inability to properly retrieve and return values

Within my code, I have a function that looks like this: $.fn.validate.checkValidationName = function(id) { $.post("PHP/submitButtonName.php", {checkValidation: id}, function(data) { if(data.returnValue === true) { name = true; } else { ...

Stop jQuery function from activating twice during scrolling

I'm looking for a solution to optimize my code that detects if an element is in the viewport and triggers certain actions. Currently, it re-runs the code every time a scroll event occurs when the element is above the fold. Is there a way to make it on ...

Creating borders around Material UI grid items can be achieved by applying a border style to the

import React from 'react'; import { makeStyles } from '@material-ui/core/styles'; import Paper from '@material-ui/core/Paper'; import Grid from '@material-ui/core/Grid'; const useStyles = makeStyles((theme) => ({ ...

Formatting numbers in JavaScript objects

I am looking to iterate through an array of objects and convert the string values into numbers. Here is a sample scenario: I have data in a format similar to the variable provided below. When passing this array to a kendo chart, it seems to have trouble r ...

Is there a way to deactivate the spin buttons for an input number field?

Is there a way to create an input element with type number in Vue using createElement() in TypeScript and then disable the spin buttons for increment and decrement? I attempted to use the following CSS: input[type=number]::-webkit-inner-spin-button, input ...

Bug in jQuery mouse hover effect causes the mouseover event to fire multiple times upon mouseout

I'm experiencing an issue with my gallery grid where a nested span displaying the title is supposed to slide up on mouseover and hide on mouseout. However, whenever the mouse moves down to the title or hovers out of the tile from the bottom, the hover ...

Modify table row background color using PHP based on its position in the table with the use of a function

I am having trouble formatting my table to highlight different rows in distinct colors. The top row should be one color, the second row another, and the bottom two rows a different color each. This is to represent winners, teams getting promoted, and tho ...

Having issues with Attributes.Add() function on ASP.NET platform

After adding CSS through code behind in asp.net on page_load, it works perfectly on my local environment but fails to work on the server. Here is the code snippet for your reference: protected void Page_Load(object sender, EventArgs e) { string selec ...

The behavior of the button type value varies between Internet Explorer and Firefox

Inside a form, I have a button with the following code: <form method="post" action=""> <button type=submit value="hello" name="submitform">World</button> </form> Interestingly, the behavior of this button type varies across differ ...

Trouble with Select2 delay function not functioning

I've implemented the following code to set up select2 on a select box. However, the delay feature doesn't seem to be working as expected as requests are being sent to the server immediately. $(".multi_select").select2({ multiple: true, a ...

Make the inner div within the td stretch to cover the entire height of the td

Inside the first tds, there is dynamic text content that automatically expands the trs and tds. However, the second tds have a div with a background image but no text inside. I want these divs with background images to expand or collapse along with the tab ...