简体   繁体   中英

How to align select and select box while select's position changed

I found a fun problem with the native html select element. when you click the select, after it the select's position change, but the box under the select won't change it's position to align with it.

在此处输入图片说明

Here is a simple code sample.

 (() => { setTimeout(() => { document.getElementById('span').innerText = "Test of metal"; }, 3000) })() 
 <div> <span id="span"></span> <select> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </div> 

how to make the box align with the select itself? Is there any solution?

Try this:

  (() => { setTimeout(() => { document.getElementById('span').innerText = "Test of metal", document.getElementById('select_id'); }, 3000) })() 
 <div> <span id="span"></span> <select id="select_id"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </div> 

change the 3000 value to faster the text shows up

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM