English 中文(简体)
Blazor Css不尊重高度(100%);
原标题:Blazor css doesn t honor height calc(100%);

This question is WHY DOES BLAZOR work differently. NOT how to make an item 100% tall.

EDUPATATE: same cs 手工编码成 HTML 文件,按需要工作。 Blazor 中的 same cs没有。

我有一个测试 HTML 页面显示 div 完全高度 。

但当应用到火衣时, css 无效。 我找不到任何文件来解释这种行为。

它看起来像calc( 100%) 在火焰中不起作用 。

<html>
    <head>
        <style>
        body {
            color: rgb(170, 170, 170);
            background-color: rgb(0, 0, 0);
            font-family: Georgia,  Times New Roman , Times, serif;
        }
        .container {
            height: calc(100%);
            background-color: red;
            margin: 0;
            padding: 0;
        }
        </style>
    </head>
    <body>
        <div class="container">container
        </div>
    </body>
</html>

Hand Coded HTML


主拉尤特. razor

@inherits LayoutComponentBase

<div class="container">container
</div>

应用( a.cs)

body {
    color: rgb(170, 170, 170);
    background-color: rgb(0, 0, 0);
    font-family: Georgia,  Times New Roman , Times, serif;
}

.container {
    height: calc(100%);
    background-color: red;
    margin: 0;
    padding: 0;
}

Blazor 应用程序

问题回答

在 Blazor 中, 组件在由 Blazor 框架动态生成的一系列嵌套的 < code@ lt; div> 元素中生成。 这可能会引起 CSS 的问题不会自动与视图端的全高度相适应 。

您需要将 html body 元素的高度明确设定为 100__/code>/ /code>,以确保容器 div 能够达到全高度。

html,body {
    height: 100vh;
    color: rgb(170, 170, 170);
    background-color: rgb(0, 0, 0);
    font-family: Georgia,  Times New Roman , Times, serif;
}

.container {
    height: calc(100%);
    background-color: red;
    margin: 0;
    padding: 0;
}

如果您也需要宽度为全宽, 您需要添加 max- width: 100%; :

.container {
    max-width:100%;
    height: calc(100%);
    background-color: red;
    margin: 0;
    padding: 0;
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...