Could you please guide me on resolving the Blazor/Bootstrap 5 CSS problem related to styling "striped" tables?

Looking for a solution to fix a CSS issue involving Bootstrap 5 "table-striped" and displaying Blazor Razor components.

In my Blazor/Bootstrap 5 page, I have a table displaying content fetched from a service at runtime. Initially, the Bootstrap CSS is visible briefly on page load, but then it seems like the Bootstrap striped CSS is being overridden by unknown dynamic styles. Despite checking in Chrome/Edge dev tools, no additional CSS styles are applied to the table other than the ones specified by me. The end result is a plain black and white table instead of the intended striped format.

The table's structure using the new striped CSS is quite basic:

<table class="table table-striped table-success">
    <thead>
        <tr>
            <th width="2%" class="text-center" scope="col">ID</th>
            <th width="98%" scope="col">Detail</th>
        </tr>
    </thead>
@if (eventList.Any())
{
    foreach (var e in eventList.Take(5).ToList())
    {
        <tr>            
            <td>@e.blahblah</td>
            <td>@e.blahblah</td>
        </tr>
    }
}
</table>

Dynamic Table Content - Bootstrap 5 CSS not working

I tried simplifying the table generation code as a test:

<table class="table table-striped table-success">
    <thead>
        <tr>
            <th class="text-center" scope="col">ID</th>
        </tr>
    </thead>
    <tr>
        <td class="text-center">
            @if (eventList.Any())
            {
                foreach (var e in eventList.Take(5).ToList())
                {
                    @e.blahblah
                }
            }
        </td>
    </tr>
</table>

Still, the Bootstrap 5 CSS continues to be overwritten by Blazor during rendering. After the initial flash of correct styling on page load, the table reverts to a simple black and white design.


To confirm, when inserting static code into the table, the striped formatting works flawlessly:

<tr>
    <td>Foo</td>
    <td>Too</td>
</tr>
<tr>
    <td>Foo</td>
    <td>Too</td>
</tr>
<tr>
    <td>Foo</td>
    <td>Too</td>
</tr>

Static Table Content - Bootstrap 5 CSS works

This appears to be related to an issue with the Blazor rendering engine. How can I preserve the Bootstrap 5 styling for tabular content generated by Blazor at runtime? What is causing the CSS override?

Seeking guidance on how to resolve this. Thank you.

Answer №1

Appreciate the insight Uxonith provided. In order to resolve the issue, it was discovered that a missing wrapper around the content was causing the problem. Here is an example of the corrected code:

<table class="table table-striped table-success">
    <thead>
        <tr>
            <th width="2%" class="text-center" scope="col">ID</th>
            <th width="98%" scope="col">Detail</th>
        </tr>
    </thead>
    <tbody>
        @if (eventList.Any())
        {
            foreach (var e in eventList)
            {
                <tr>
                    <td class="text-center">@e.Id</td>
                    <td>@e.EventInfo</td>

                </tr>
            }
        }
    </tbody>
</table>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Container for grid template columns and responsive window in a single row

Imagine having around 250 divs with the class slider-item styled in a certain way. You have a responsive grid in CSS called A which arranges these divs as columns/items when the window resizes, with a minimum item width of 240px. Check out how it looks bel ...

Issue with CSS min-height causing divs to not align properly

My CSS Code includes media queries to adjust the layout: .clearfloat { clear: both; font-size: 1px; height: 0; line-height: 0; } .box-container { width:100%; text-align:center; } .icon-box { width:32%; max-width:500px; ...

What is the best way to incorporate sound into an asp.net web page?

I am trying to add sound effects to my webpage when a button is clicked. However, I keep encountering an error with the following code: SoundPlayer audio = new SoundPlayer(); audio.SoundLocation = "WindowsBalloon.wav"; //audio.Play(); audio.PlaySync(); T ...

Having trouble incorporating custom CSS into my Rails/Bootstrap project

I’m having trouble figuring out what I’m doing wrong. I’ve added custom files and tried to override the existing ones. application.css.scss @import 'bootstrap-sprockets'; @import 'bootstrap'; /* * This manifest file will be co ...

Implementing overflow-x: hidden in React JS for enhancing mobile user experience

In my current React project, I encountered an issue where setting overflow-x: hidden in the index.css file for the body tag worked fine on desktop screens but not on mobile. I read that adding it to the parent element would be a better solution, however, ...

Drawer component from Material-UI placed on top of the sidebar

Currently, I am working on a project where I am using React TypeScript along with Material-UI. The issue that I am encountering is related to the width of the Drawer component provided by Material-UI. By default, the Drawer takes up the entire screen wid ...

How can I send an HTML document from a WebApi 2 action using the IHttpActionResult interface?

When it comes to building an html document and returning it in a web api, many resources recommend using HttpResponseMessage. However, I am eager to achieve this using IHttpActionResult instead. Here is my current approach: [ResponseType(typeof(HttpRe ...

adjusting iframe dimensions for iPads

I am dealing with an HTML file that contains the following code snippet: <table height="100%" cellspacing="0" cellpadding="0" border="0" width="646" class="data border"> <tbody> <tr> <td valig ...

What is the best way to conceal a Material UI button with CSS?

For my TODO react app, I am using a Material UI button. My goal is to create a form with an input field and a submit button, but I want the submit button to be invisible so that users think the form submits when they press the "Return" key. import { Tex ...

Create an HTML table with a line separating two table cells

I need help with creating a table row and td's dynamically using basic HTML and CSS. I would like to draw lines between the td's similar to the example image shown below. Can someone please assist me in achieving this? https://i.sstatic.net/GPd ...

Building a Horizontal Line Component in ReactJS

Looking for help with my login page design. I have two login buttons - one for regular login and one for Google login. I want to add a stylish horizontal line with the word "OR" between the buttons, similar to the image in the link provided. https://i.sst ...

Pushing down menu items in a dropdown CSS navigation bar

I have a vertical navigation menu with parent and non-parent items. I want the parent items to display their child pages when hovered over, while also pushing down the items above them. HTML: <nav class="main"> <ul> <li> ...

Can <option> tags be arranged side by side using CSS?

Here is a form I am working with: <form action="file.php" method="GET"> <input type="hidden" name="page"> <select> <option>Text 1</option> <option>Text 2</option> <option>Text 3 ...

Changing the background color completely

Need help with CSS! I have two divs, one with a background color of #000 and the other with a transparent PNG image as the background. I want to override the background color with transparency from the PNG file so that the background doesn't cover th ...

Show on smartphones, conceal on desktops - Activation/URL

I'm attempting to create a click-to-call link on my website using the following: <a class="mobile-only" href="tel:+534306464456"><p class="">Click Here to call us</p></a> I want this link to only show up on mobile devices, sp ...

a guide on displaying information through JSON

HOW TO SOLVE the error in Unity 3D Json Exception: Input is not valid JSON text LitJson.JsonReader.Read () I am working on developing a quiz game that displays questions and answers on buttons. How can I fix this issue to ensure the ...

Implementing the style tag within a view

In my exploration of various Razor views, I've noticed a common practice where developers include a <style> tag directly in the CSHTML file. While this method may seem to work without issue, it actually places the <style> tag within the & ...

Universal approach to verifying dependencies associated with an entity

I am utilizing the Entity Framework and am in a situation where I need to evaluate whether an entity has any dependencies that would necessitate a status change on an item. However, this status change can only be executed if there are no related dependen ...

Ways to eliminate the vertical scroll feature in a kendo chart

I am encountering an issue while loading a kendo chart inside grid-stack.js where I am unable to resize the height properly. Whenever I decrease the height, a vertical scroll appears which should not happen. I have tried setting the height to auto and refr ...

Avoiding the appearance of a scrollbar when content extends beyond its containing block

I am struggling with writing markup and CSS to prevent a background image from creating a scrollbar unless the viewport is narrower than the inner content wrapper: The solution provided in this post didn't work for me: Absolutely positioned div on ri ...