Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align selected item in scrolling html dropdown [duplicate]

I have a scrolling dropdown, and when someone opens the dropdown, I want the currently selected element to show in the center (if possible, aka it's low/high enough), instead of the browser default - in Firefox, the dropdown view shows the selected element at the end.

undesired desired

like image 363
notablytipsy Avatar asked May 21 '20 17:05

notablytipsy


People also ask

How do I keep my Div fixed when scrolling?

If the vertical scroll is more than the element's position, the position property is set to 'fixed', and the 'top' property is given a value of '0px'. Otherwise, the position is set to 'relative', and the 'top' property is reset using the 'initial' value.

How do I scroll to a specific section in HTML?

By using an href attribute inside an anchor tag you can scroll the page to a specific element using a # in front of the elements id name.

What is scroll snap align?

The scroll-snap-align property specifies the box's snap position as an alignment of its snap area (as the alignment subject) within its snap container's snapport (as the alignment container). The two values specify the snapping alignment in the block axis and inline axis, respectively.


2 Answers

Unfortunately, you can't do that with your default select options.

This question is already answered here.

Anyway, you could build a custom select or could use plugin for custom select and then position the dropdown:

https://select2.org/

http://gregfranko.com/jquery.selectBoxIt.js/

like image 170
Leon Vuković Avatar answered Oct 10 '22 12:10

Leon Vuković


I think this can be possible you can center the selected ones but not all the options so the selected ones you can center it like

<!DOCTYPE html>
<html>

<head>
  <title></title>
  <style>
    select {
      width: 400px;
      text-align-last: center;
    }
  </style>
</head>

<body>
  <select name="state" class="ddList">
    <option>Selected</option>
    <option>A</option>
    <option>B</option>
    <option>C</option>
    <option>D</option>
  </select>
</body>

</html>
like image 27
Umutambyi Gad Avatar answered Oct 10 '22 12:10

Umutambyi Gad