How to display an element to the center of the browser

Sometimes you might need to display an element, for example a div, to the center of the browser. Here is an example of how you can do it using JavaScript and CSS. functioninit(){// Reference to the element varloading=document.getElementById("loading");// The div's width, set within the CSS class varloadingWidth=loading.offsetWidth;// The div's width, set within the CSS class varloadingHeight=loading.offsetHeight;// The browser's body's width vardocumentWidth=document.body.clientWidth;// The browser's body's height vardocumentHeight=document.body.clientHeight;// Position the element absolutely loading.

How to add scrollbars to a block (e.g. a <div> element)

If you need to customize a list box then the <select> HTML element might not be enough. In such a case you’d like to have something that simulates the <select> behaviour. Here is the code to use to obtain a custom list box: <html><head></head><body><divstyle="width: 200px; height: 200px; overflow: auto;"><tablewidth="100%"height="100%"><script>for(vari=0;i<30;i++){if(i%2==0){document.write("<tr style='background-color:#0066ff; color: #ffffff'>"+"<td>JavaScript</td></tr>");}else{document.write("<tr style='background-color:#ff6600; color: #ffffff'>"+"<td>JavaScript</td></tr>");}}</script></table></div></body></html> The key CSS element is overflow. If you use overflow: auto then the scrollbars are displayed only if they are needed.