Sticky CSS styles not working in MudBlazor project

I am working on a Blazor project using MudBlazor components. I need to make some text boxes and a search button stick to the top of the MudGrid while scrolling. I tried using position: sticky and top: 0, which works in a Blazor snippet but not in my MudBlazor project.

Here is the relevant part of my code:

@page "/searchapp"
@inject IApplicationTableService ApplicationService
@using MudBlazor
@using BlazorAppDB.Shared.Models

<style>
    .custom-width {
        width: 100px;
    }

    .header {
        position: sticky;
        top: 0;
        background-color: white;
        padding: 10px;
        z-index: 1000;
    }

    .input-group {
        display: flex;
        align-items: center;
    }

    .input-group .mud-button {
        margin-left: 10px;
    }

    .mud-spacing {
        margin-bottom: 10px;
    }

    .small-textfield {
        width: 150px; /* Adjust the width as needed */
    }
</style>

<div style="margin-top: 20px;">
    <MudChip Style="width: 100%;" Color="Color.Primary" Variant="Variant.Text" Icon="@Icons.Material.Filled.FormatListBulleted" Size="Size.Small">
        <b>Search for an application in the App Inventory</b>
    </MudChip>
</div>

<div style="display: flex; align-items: center; justify-content: center;">
    <MudIcon Icon="@Icons.Material.TwoTone.DatasetLinked" Color="Color.Default" Size="Size.Large" />
    <MudText Typo="Typo.subtitle1">
        <b>SEARCH THE APPS DATABASE</b>
    </MudText>
</div>

<div class="header">
    <div class="input-group mud-spacing">
        <MudGrid>
            <MudItem xs="12" md="3" class="custom-width">
                <MudTextField @bind-Value="applicationName"
                              Label="Application Name"
                              AnchorOrigin="Origin.BottomCenter"
                              Variant="Variant.Outlined"
                              Clearable="true"
                              Margin="Margin.Dense"
                              AdornmentColor="Color.Dark"
                              Immediate="true" />
            </MudItem>

            <MudItem xs="12" md="3" class="custom-width">
                <MudTextField @bind-Value="applicationType"
                              Label="Application Type"
                              AnchorOrigin="Origin.BottomCenter"
                              Variant="Variant.Outlined"
                              Clearable="true"
                              Margin="Margin.Dense"
                              AdornmentColor="Color.Dark"
                              Immediate="true" />
            </MudItem>

            <MudItem xs="12" md="3" class="custom-width">
                <MudTextField @bind-Value="applicationOwner"
                              Label="Application Owner"
                              AnchorOrigin="Origin.BottomCenter"
                              Variant="Variant.Outlined"
                              Clearable="true"
                              Margin="Margin.Dense"
                              AdornmentColor="Color.Dark"
                              Immediate="true" />
            </MudItem>

            <MudItem xs="12" md="3">
                <MudButton Variant="Variant.Filled"
                           Color="Color.Primary"
                           OnClick="SearchApplications"
                           Class="custom-width">
                    Search
                </MudButton>
            </MudItem>
        </MudGrid>
    </div>
</div>

<MudDataGrid Items="@applications" Filterable="true" Hover="true" SortMode="SortMode.None" RowsPerPage="10" LoadingProgressColor="Color.Info" Groupable="false" FixedHeader="true" Height="600px" Expandable="true">
    <Columns>
        <PropertyColumn Property="x => x.AppId" Title="App ID" />
        <PropertyColumn Property="x => x.AppInfoId" Title="App Info ID" />
        <PropertyColumn Property="x => x.ApplicationName" Title="App Name" />
        <PropertyColumn Property="x => x.ApplicationOwner" Title="App Owner" />
        <TemplateColumn Title="App Description">
            <CellTemplate Context="cellContext">
                <MudTooltip Text="@cellContext.Item.DescriptionoftheApplication">
                    <MudTextField Value="@cellContext.Item.DescriptionoftheApplication" ReadOnly="true" Variant="Variant.Text" />
                </MudTooltip>
            </CellTemplate>
        </TemplateColumn>
        <PropertyColumn Property="x => x.BusinessFunction" Title="Business Function" />
        <TemplateColumn Title="App Type">
            <CellTemplate Context="cellContext">
                <MudTooltip Text="@cellContext.Item.ApplicationType">
                    <MudTextField Value="@cellContext.Item.ApplicationType" ReadOnly="true" Variant="Variant.Text" />
                </MudTooltip>
            </CellTemplate>
        </TemplateColumn>
        <PropertyColumn Property="x => x.IstheapplicationSsoenabled" Title="SSO Enabled" />
        <PropertyColumn Property="x => x.Snowcmdbid" Title="SNOW CMDB ID" />
        <TemplateColumn Title="Support DL">
            <CellTemplate Context="cellContext">
                <MudTooltip Text="@cellContext.Item.SupportDl">
                    <MudTextField Value="@cellContext.Item.SupportDl" ReadOnly="true" Variant="Variant.Text" />
                </MudTooltip>
            </CellTemplate>
        </TemplateColumn>
        <PropertyColumn Property="x => x.SnowqueueName" Title="SNOW Queue Name" />
        <PropertyColumn Property="x => x.Comment" Title="Comment" />
        <TemplateColumn Title="Owner Email">
            <CellTemplate Context="cellContext">
                <MudTooltip Text="@cellContext.Item.OwnerEmail">
                    <MudTextField Value="@cellContext.Item.OwnerEmail" ReadOnly="true" Variant="Variant.Text" />
                </MudTooltip>
            </CellTemplate>
        </TemplateColumn>
        <PropertyColumn Property="x => x.ContactEmail" Title="Contact Email" />
        <PropertyColumn Property="x => x.Platform" Title="Platform" />
    </Columns>
    <PagerContent>
        <MudDataGridPager />
    </PagerContent>
</MudDataGrid>

<MudText><b>If you didn't find the app you were looking for, try a new search.</b></MudText>
<MudText><b>If your app was not in the DB, please consider creating an entry for it using this link.</b> <a href="/createapp" style="color: blue;">Create App</a></MudText>

@code {
    private IEnumerable<ApplicationTable> applications = Enumerable.Empty<ApplicationTable>();

    private string applicationType;
    private string applicationName;
    private string applicationOwner;

    protected override async Task OnInitializedAsync()
    {
        try
        {
            applications = await ApplicationService.GetAllApplicationsAsync();
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error fetching applications: {ex.Message}");
            applications = Enumerable.Empty<ApplicationTable>();
        }
    }

    private async Task SearchApplications()
    {
        try
        {
            applications = await ApplicationService.SearchApplications(applicationType, applicationName, applicationOwner);

            if (!applications.Any())
            {
                Console.WriteLine("No applications found.");
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error fetching applications: {ex.Message}");
            applications = Enumerable.Empty<ApplicationTable>();
        }
    }
}

I have tried using position: sticky and top: 0 on the .header class, but it doesn’t seem to work in my MudBlazor project. How can I fix this issue?

New contributor

roja rose is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật