Html CSS 设置默认滚动位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/953083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:51:01  来源:igfitidea点击:

CSS set default scroll position

htmlcss

提问by fmsf

Is there any way to set the scroll position to a default value?

有没有办法将滚动位置设置为默认值?

I know how to do it in javascript, for example with jquery:

我知道如何在 javascript 中做到这一点,例如使用 jquery:

$("div#divWithScroll").attr("scrollTop",200);

But I wanted to do it with css only, I have no idea if it is possible.

但我只想用 css 来做,我不知道是否可能。

采纳答案by abstraktor

Within boundaries, it is possible:

在边界内,可能:

When you go to the url www.domain.com/#divWithScrollthen you will scroll down by default.

当您转到 urlwww.domain.com/#divWithScroll时,默认情况下您将向下滚动。

<a href="#divWithScroll">Scroll down</a><!-- clicking this works either -->
<!-- long blablabla -->
<div id="divWithScroll">Scrolled here</div>

More on http://css-tricks.com/hash-tag-links-padding/

更多关于http://css-tricks.com/hash-tag-links-padding/

回答by RichieHindle

No, there's no way to do that in CSS. Sorry!

不,在 CSS 中没有办法做到这一点。对不起!

回答by Evan Meagher

It's not really a "style" issue, so it's not something that CSS would cover.

这不是真正的“样式”问题,因此 CSS 不会涵盖它。