I have a web page. It has too much height; in that page I have a div in the bottom of the page. I want to display the div in the center portion of the page. It’s appearing in the center of the page at the bottom position as in a way I l开发者_如何转开发ike , but scrolling is needed. Is it possible to set focus on that div without scrolling?
Place an anchor tag on top of the div. And add a bit of code in the page load [if it is to be shown when the page loads]
location.href = "#youranchorid";
You can put an href like this on top of the page Link to My Div
and put another href href=# name="mydiv" like this with a name called mydiv in the div tag you want to link to.
You can use javascript to accomplish this by writing:
document.getElementById("your_element_id").focus();
This will do your work:
document.getElementById('yourElementId').scrollIntoView();
精彩评论