Ensure that the preceding and succeeding list items are vertically aligned with the active item

I am working on a fixed vertical list (ul) that takes up 100% of the screen height. I want to show one active item with previous items displayed above and next items displayed below. I'm unsure if this is doable, so any thoughts or suggestions would be highly valued!

https://i.sstatic.net/8uvfy.jpg

Answer №1

To achieve the desired layout, you can utilize the CSS property

display: flex; flex-direction: column;
for the list, and then apply
flex-grow: 1; display: flex; align-items: center;
to the active element. This will cause the active element to expand and occupy all available space while vertically centering its contents.

* {margin:0;padding:0}
ul {
  height: 100vh;
  display: flex;
  flex-direction: column;
  list-style: none;
}
.active {
  flex-grow: 1;
  display: flex;
  align-items: center;
}
<ul>
  <li>foo</li>
  <li>foo</li>
  <li class="active">foo</li>
  <li>foo</li>
  <li>foo</li>
</ul>

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

The method provided by the FullScreen API is not effective in cancelling the fullscreen mode

After testing my code in Google Chrome, I encountered the following error message: Uncaught TypeError: Object #<HTMLDivElement> has no method 'webkitCancelFullScreen' Interestingly, I also received a similar error while running the code i ...

Choosing an input option after the second ajax call is finished with JQuery

I'm fetching data from MySQL to PHP using AJAX. I am trying to implement an edit feature on my website within a modal window. The select input with options (subcategories) is loaded via AJAX after the radio input categories are loaded by a previous AJ ...

Steps for automatically toggling a button within a button-group when the page is loaded using jQuery in Bootstrap 3

Here is a button group setup: <div class="btn-group" data-toggle="buttons"> <label class="btn btn-default"> <input type="radio" name="environment" id="staging" value="staging" />Staging </label> <label class= ...

Firebase authentication encountered an error due to a network request failure

Utilizing firebase Hosting to host my website, I am encountering a persistent error when attempting to login using email/password. This is the JavaScript code that I am using: window.onload = () => initApp(); //Initialize screen function initApp(){ ...

How to modify an array in an HTML document using BeautifulSoup

Running a Python script, I am trying to access a local HTML file containing a JavaScript array inside a script tag that needs updating. Here is the test code snippet: from bs4 import BeautifulSoup html = ''' <script> var myArray ...

Error encountered when attempting to retrieve JSON data in JavaScript due to being undefined

A snippet of code that reads and writes JSON data is presented below: var info; $(function () { $.getJSON("data.json", function (d) { info = d; }); $('.btn').click(function () { info['c-type'] = $('#c- ...

Flex items refusing to wrap in a flexbox with a column-direction orientation

In my code, I am using an outerWrapper, innerWrapper, and children. The outerWrapper has a fixed height of 300px and is styled with display: flex. Similarly, the innerWrapper also has a style of display: flex with flex-direction: column. However, when I a ...

Making a colorful box within a paragraph using a span element

Check out my code snippet: <p style="font-size: 12px;line-height: 24px;font-weight: normal;color: #848484;padding: 0;margin: 0;"><b>COLOR:</b> <span style="width: 15px; height: 15px; margin:auto; display: inline_block; b ...

Utilize JavaScript to redirect based on URL parameters with the presence of the "@ symbol"

I need help redirecting to a new page upon button click using a JS function. The URL needs to include an email address parameter. <form> <input type="email" id="mail" placeholder="ENTER YOUR EMAIL ADDRESS" requir ...

Display Div when scrolling near the top, not the bottom

I found this code snippet on Stack Overflow that shows a div when the bottom scrolls into view. However, I need it to show the div when the top scrolls into view instead. How can I make this adjustment? Here's the JS Fiddle link $(document).ready ...

Wrapping content in Vue/Vuetify into columns according to screen size

I am working on a parent component that uses a v-for to render instances of the product-box component based on the number of products. Currently, when there are 200 products, they simply stack on top of each other extending the page length like this: [box ...

Obtain the identification address for a group of items

I have a JSON object containing place IDs, and I am attempting to retrieve the corresponding addresses for each ID. This is the code snippet I'm using: <div id="places" class="places"></div> <script> function initialize() { j ...

Using JQuery to implement a date and time picker requires setting the default time based on the server's PHP settings

I have implemented a jQuery UI datetime picker in my project. As JavaScript runs on the client side, it collects date and time information from the user's machine. Below is the code snippet I am currently using: <script> // Function to set ...

PHP - Showing Json formatted messages

Currently, I am in the process of constructing an AJAX form using jQuery and PHP. The PHP script is responsible for validating the data submitted and transmitting back messages that are encoded in JSON format. In case JavaScript is disabled, the messages w ...

How can I adjust the alignment of my menu items to be centered without using flexbox?

Even though I've searched extensively on how to center text horizontally, none of the suggestions have worked for me. I attempted using margin-left: auto, margin-right: auto, and text-align: center for the class nav-center, but none of them had the de ...

Exporting MySQL data to MS Excel is functioning smoothly on the local environment, however, it is encountering difficulties when

<title>Orders Export</title> <body> <?php header('Content-Type: application/xls'); header('Content-Disposition: attachment; filename=download.xls'); $con = mysqli_connect('localhost','suresafe ...

What is the process for updating the value of an input field?

I am facing a challenge with a dynamic form that includes input, text, and select elements. The form is identified by the ID #user-form, and my goal is to update the values of the input/select/text elements within this form. One of the elements in the for ...

What is the best way to change the height of a div element as the user scrolls using JavaScript exclusively?

Coding with JavaScript var changeHeight = () => { let flag = 0; while(flag != 1) { size += 1; return size; } if(size == window.innerHeight/2){ flag == 1; } } var size = 5; document.body.style.height = &qu ...

Include the window.innerWidth value in the initial GET request

When dealing with a server-side rendered app that has responsive styling based on window.innerWidth, the challenge lies in how to pass the client's screen size in the initial GET request for index.html. This is crucial so that the server can prepare a ...

Storing css data for iPhone Facebook application

Currently, I am in the process of developing a webpage specifically for the iPhone Facebook app wall link. Interestingly, when attempting to apply the margin attribute to a div within the webpage, the margin doesn't seem to have any effect when clicki ...