如何仅在某些页面中禁用溢出

发布于 2025-02-14 01:54:43 字数 148 浏览 0 评论 0原文

我正在从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我是有多爱你 2025-02-21 01:54:43

我认为您可能可以将其应用于布局。这完全取决于您是否在托管CSHTML页面中做任何事情。

创建现有布局的副本,然后将样式应用于顶部page元素。

修改CSS文件中的page元素。

.page {
    position: relative;
    display: flex;
    flex-direction: column;
    overflow:hidden;
}

这是我的测试页面 - 我的新布局是baselayout.razor:

@layout BaseLayout
@page "/"

<div style="width:3000px" class="bg-black text-white">
<h1>Hello</h1>
</div>

@code {
}

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.

.page {
    position: relative;
    display: flex;
    flex-direction: column;
    overflow:hidden;
}

Here's my test page - my new Layout is BaseLayout.razor:

@layout BaseLayout
@page "/"

<div style="width:3000px" class="bg-black text-white">
<h1>Hello</h1>
</div>

@code {
}
提笔书几行 2025-02-21 01:54:43

您可以级联布局并从任何后代设置课程。这是一个简化的版本 - 实际上,您需要更仔细地控制如何设置类变量 - 但是您可以得到基本想法。请注意,@body不是HTML主体,而是大餐内容。

mainlayout.razor

<div class="@LayoutClass">
    <CascadingValue Value="this">
       @body
    </CascadingValue>
</div>

@code{
    public string LayoutClass = "layout-default";
}

anychild.razor

@code{
  [CascadingParameter]
  public MainLayout? Main { get; set; }

  void ChangeRootClass(){
     if (Main is not null) Main.LayoutClass = "AlternatePageClass";
  }
}

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

<div class="@LayoutClass">
    <CascadingValue Value="this">
       @body
    </CascadingValue>
</div>

@code{
    public string LayoutClass = "layout-default";
}

AnyChild.razor

@code{
  [CascadingParameter]
  public MainLayout? Main { get; set; }

  void ChangeRootClass(){
     if (Main is not null) Main.LayoutClass = "AlternatePageClass";
  }
}
述情 2025-02-21 01:54:43

为了通过对模板进行较小的更改来解决您的问题,我建议默认情况下将滚动条关闭。

中,mainlayout.razor.css将以下行添加到.page

.page {
    ...
    overflow: hidden;
}

&lt; aCTECT/&gt;元素需要以大小固定。该模板使用.top-Row使用高度:3.5REM;

在下面的同一文件中main add:

article {
    height: calc(100vh - 3.5rem);
    max-height: calc(100vh - 3.5rem);
}

在此阶段默认情况下,条形符合条,&lt; atrate/&gt;元素占据了屏幕的其余部分。

要使页面滚动很容易,只需将内容包装在Div中:

<div class="h-100 overflow-auto">
    ...
</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

.page {
    ...
    overflow: hidden;
}

The <article /> element needs to be fixed in size. The template uses a .top-row that has uses height: 3.5rem;

In the same file below main add:

article {
    height: calc(100vh - 3.5rem);
    max-height: calc(100vh - 3.5rem);
}

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:

<div class="h-100 overflow-auto">
    ...
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文