liveBook · Manning

Bootstrap

As explained in Pro ASP.NET Core 7, Tenth Edition

Bootstrap is an open-source front-end CSS framework for building web interfaces with predefined styles and components.

Bootstrap is a CSS framework for improving the appearance of HTML without writing every style from scratch. Add its stylesheet to the page, then assign Bootstrap classes to elements. In an ASP.NET Core application, those elements may come from static HTML, Razor views, tag helpers, or Blazor WebAssembly components. section 3.2.10 section 15.4.2 section 37.3.4

Install the client-side package with Library Manager (LibMan). Initialize the project with `libman init -p cdnjs`, then run `libman install bootstrap@5.2.3 -d wwwroot/lib/bootstrap`. The `-d` option selects the destination; `wwwroot/lib` is the usual location for client-side packages. Link the installed CSS file from the HTML sent to the browser. Check the installed directory before copying a path: examples use both `/lib/bootstrap/css/bootstrap.min.css` and `/lib/bootstrap/dist/css/bootstrap.css`. section 4.4.3 section 3.2.10

Put the link where the relevant pages can use it, then apply classes to their HTML:

  • For a static page, link `/lib/bootstrap/css/bootstrap.min.css` and give a heading classes such as `p-2 bg-primary text-white`. Static file middleware serves the stylesheet from `wwwroot` when the browser requests it. section 15.4.2
  • For shared Razor views, link the stylesheet in `_Layout.cshtml`; views using that layout can then use its styles. A view can style product cards, badges, and pagination links. section 7.5.2
  • For Blazor WebAssembly, an `index.html` link can use the Bootstrap copy installed in the ASP.NET Core project instead of the template’s copy. section 37.3.4

Styling an RSVP link

In `Views/Home/Index.cshtml`, link the Bootstrap stylesheet and write `<a class="btn btn-primary" asp-action="RsvpForm">RSVP Now</a>`. The `btn` class gives the link button styling; `btn-primary` chooses its color. A surrounding `text-center` class centers its contents. The link still targets the RSVP action—Bootstrap changes its appearance, not that destination. section 3.2.10

Keep styling choices out of a reusable tag helper when possible. A pagination helper can accept classes through attributes such as `page-class="btn"` and `page-class-selected="btn-primary"`, then apply them to the links it generates. Bootstrap is used here as a practical styling tool, not as a full tour of its classes or components. section 7.5.2 section 4.4.3

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Shows installation, stylesheet links, and applied classes; defers comprehensive Bootstrap details to its documentation.
Examples
Uses an RSVP link, styled static heading, product cards, and pagination links.
What it assumes
Assumes basic HTML and ASP.NET Core project structure, while showing the commands needed to install the client-side package.
What you can do after
Apply it via LibMan to install Bootstrap and style ASP.NET Core HTML with linked stylesheets and classes.
How it connects
Connects CSS classes with LibMan, static file middleware, Razor layouts, tag helpers, and Blazor WebAssembly.

Also explained in

Compare how 3 books explain Bootstrap →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.