Vertically centered sidebar now stationary

I'm looking to create a website with a fixed sidebar positioned at the center of the screen on the left-hand side. I want it to remain vertically centered even when the page is scrolled.

Is there a way to achieve this effect using pure CSS/HTML?

I've considered updating the sidebar's position on scroll, but I'm concerned about potential flickering caused by constant updates to its top position in the CSS. Are there any alternative solutions available? Ideally, I'd like to stick to CSS alone, but I'm open to utilizing jQuery if it can deliver the functionality I need.

Answer №1

To ensure it stays in place, consider including position: fixed; in the CSS code.

Answer №2

Here is the solution you've been searching for. It's important to keep in mind that mobile browsers tend to disregard the position:fixed property, so you'll need to incorporate some JavaScript to ensure it works properly on those devices. Be sure to set the container's minimum height to 200px.

#sidebar
{
    height: 200px;
    position: fixed;    /* Keeps element in place when scrolling */
    top: 50%;       /* Moves down 50% from top of container */
    margin-top: -100px; /* Adjusts back up half the height of this element */
}

#container
{
    min-height: 200px;
    _height: 200px; /* Specifies height for IE6 since it treats height as min-height unless overflow is hidden */
}

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

Exploring array data retrieval in Angular

I need to display various inch sizes for different bike models. I have a json file containing an array of bike data. [{ "name": "Mountainbike", "img_url": "assets/img/mountainbike.jpg", "mount_size": [{&quo ...

Using jQuery to update a PrimeFaces command button inside a data table

I need help adding a click function with jquery to commandButtons inside data tables rows. When the button is clicked, it should show a dialog whose content I want to build using javascript. However, I've noticed that the function defined in the javas ...

"Organizing Your Content: A Guide to Grouping Information under Specific

How can I organize content under different headings? I am using two methods to retrieve data: 1. axios.get('/api/get/headers') 2. axios.get('api/get/contents') I am struggling with how to properly structure this, especially since the ...

Reactjs rendering problem related to webpack

Greetings! I am new to using react js and decided to create a quiz application. However, I encountered an error when the render function was called. Below is my webpack.config file: module.exports = { entry: { app: './src/index.js' }, ...

Harnessing the Power of Google Apps Scripts: Mastering the Art of Handling Comma-Separated Spreadsheet Values Transformed

I have a spreadsheet where column 1 contains source file IDs, with each cell holding only one ID. Column 2 has destination file IDs, where cells contain multiple IDs separated by commas. I utilize a script to retrieve these values and perform various opera ...

"I am looking for a way to retrieve dynamic data from a (click) event in Angular. Can

Within my component, I have a video loaded in an i tag on a click event. The challenge is accessing the video ID from the video.component.ts file in order to dynamically load a new video. The solution has been elusive so far. <li *ngFor="let video of c ...

Comparison of Jquery autocomplete performance: Would php/mysql/jquery or html/json/jquery be quicker? I am comparing two different scripts to determine which one is superior in terms of speed and efficiency

I am currently working with two different autocomplete scripts. One of them utilizes (A) PHP/MySQL/HTML/jQuery, while the other makes use of (B) HTML/jQuery/JSON. While I understand that these scripts are built using different technologies, making direct ...

The white background of the .jpg image is conflicting with the white background of the HTML

My website has a top-of-page .jpg image that was created with a white background. However, when using the img src="topOfEveryPageImage.jpg" tag, the white background of the image appears visually different from the rest of the solid white background on the ...

Managing login API tokens in Vue JS

I have implemented a custom Login component in my Vue project: var Login = Vue.extend({ template: '#auth', data: function () { return {username: '',password: '',errorMessage:''}; }, methods : ...

Extracting auto-populate suggestions from MySQL database

I am currently using a Jquery autosearch function that works well with hardcoded availableTags, but I would like to be able to select them from a database instead. <script> $(document).ready(function(){ $("#tabs").tabs(); var av ...

Align labels on top and inputs at the bottom using Bootstrap

I'm facing an issue with alignment in my form using Bootstrap 4.4. Whenever a select element is included, it disrupts the layout by breaking the alignment of labels and inputs on the same row. Is there a way to always keep the labels at the top and t ...

The dropdown menu is extending beyond the bounds of the screen on mobile devices

When viewing my website on a mobile device, the select dropdown is going off the screen. I am using the bootstrap class form-control. Here is my code: <select name="service" formControlName="service" class="form-control shadow-none" style="width:100%"& ...

Is it possible to line up Ajax request in Javascript?

I am seeking a way to schedule an Ajax request to occur every second. The code I currently have in place functions flawlessly. window.onload = function () { setTimeout(doStuff, 1000); // Wait before continuing } function doStuff() { ...

Guidance on executing a JavaScript function from PHP or HTML

Although this may appear simple to some, I am relatively new to this and have been searching everywhere. I currently have a javascript function. mkfile : function(fm) { I am attempting to run this from an on-click event. Any suggestions? I apologize fo ...

Struggling to display the Three.js LightMap?

I'm having trouble getting the lightMap to show on my mesh. Here's the code I'm using: loader.load('model.ctm', function (geometry) { var lm = THREE.ImageUtils.loadTexture('lm.jpg'); var m = THREE.ImageUtils.loadT ...

Having issues with jQuery append() function not working when concatenating strings

(See complete code below) This specific part of the code $('#' + id).parent().append('<div id="pop-up">hello</div>'); functions correctly. However, when I attempt to use this alternative approach $('#' + id).p ...

How can I allow scrolling on a background image with a fixed position?

I am trying to apply a full-page width background to a container-fluid element by giving it a position of fixed and height of 100%. However, I'm encountering an issue where the page scrolls when the content exceeds the height of the browser. The proje ...

"Encountering an issue with Asp.net:FullCalendar where events are not

Hey there! I've been trying to set up FullCalendar on my ASP.NET application by following some tutorials, but unfortunately, when I launch my application, the calendar isn't loading the events. Here's a snippet from my index.chtml file: @{ ...

I am new to javascript and jquery. I have encountered numerous cases involving audio players

Recently delved into learning javascript and jquery. I managed to create a basic audio player that plays short audio clips. However, I've encountered an issue where clicking the play button on one clip displays stop buttons on all clips instead of on ...

Strategies for Preserving Added Field Data Using JQuery

I am working on a code that dynamically adds fields to a form, you can see it in action on this jsFiddle. My question is, is there a way to keep the newly added fields even after the form is submitted and the user returns to the page? I'm not looking ...