如何仅在某些页面中禁用溢出
我正在从Visual Studio模板开始构建一款Blazor Server应用程序。
我只需要在一页上禁用溢出滚动条。 添加html,身体{溢出:隐藏; }
在相对Blazor组件的CSS中不起作用。
该项目已经有一个站点。
I am building a Blazor server app starting from the Visual Studio template.
I need to disable overflow scroll bars only for one page.
Adding html, body { overflow : hidden; }
in the relative Blazor component's css it does not work.
The project has already a site.css, if I add the overflow : hidden;
in there it works but, of course, it will disable it for the whole site.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您可能可以将其应用于布局。这完全取决于您是否在托管CSHTML页面中做任何事情。
创建现有布局的副本,然后将样式应用于顶部
page
元素。修改CSS文件中的
page
元素。这是我的测试页面 - 我的新布局是baselayout.razor:
I think you can probably apply it to the Layout. It all depends on whether you're doing anything out of the ordinary in the hosted cshtml page.
Create a copy of the existing Layout and apply the style to the top
page
element.Modify the
page
element in the css file.Here's my test page - my new Layout is BaseLayout.razor:
您可以级联布局并从任何后代设置课程。这是一个简化的版本 - 实际上,您需要更仔细地控制如何设置类变量 - 但是您可以得到基本想法。请注意,
@body
不是HTML主体,而是大餐内容。mainlayout.razor
anychild.razor
You could cascade your Layout and set the class from any descendent. This is a simplified version-- in reality, you'd want to more carefully control how you set the class variable-- but you can get the basic idea. Note that
@body
isn't the html body, it's the Blazor content.MainLayout.razor
AnyChild.razor
为了通过对模板进行较小的更改来解决您的问题,我建议默认情况下将滚动条关闭。
在
中,mainlayout.razor.css
将以下行添加到.page
< aCTECT/>
元素需要以大小固定。该模板使用.top-Row
使用高度:3.5REM;
在下面的同一文件中
main
add:在此阶段默认情况下,条形符合条,
< atrate/>
元素占据了屏幕的其余部分。要使页面滚动很容易,只需将内容包装在Div中:
To solve your problem with minor changes to the template I suggest making scrollbars off by default.
In
MainLayout.razor.css
add the following line to.page
The
<article />
element needs to be fixed in size. The template uses a.top-row
that has usesheight: 3.5rem;
In the same file below
main
add:At this stage the scroll bars are off by default and the
<article/>
element occupies the remainder of the screen.To make a page scroll is easy, just wrap the content in a div: