The commend way to install client-side dependencies like Bootstrap in ASP.NET Core is via Bower ( using bower.json, as shown above ). The habit of npm/NuGet are shown to demonstrate how easily Bootstrap can be added to other kinds of web applications, including earlier versions of ASP.NET. You can besides install bootstrap using one of several package managers, such as arbor, npm, or NuGet. In each case, the process is basically the same : There are respective ways to get started with Bootstrap. If you ’ re starting a newfangled web lotion in Visual Studio, you can choose the default newcomer template for ASP.NET Core, in which case Bootstrap will come pre-installed :
The most basic Bootstrap template looks very much like the _Layout.cshtml file shown above, and merely includes a basic menu for navigation and a place to render the remainder of the page .
Basic Navigation¶
The default template uses a adjust of
elements to render a top navbar and the chief body of the page. If you ’ re using HTML5, you can replace the first gear
tag with a
tag to get the lapp effect, but with more precise semantics. Within this first
you can see there are several others. First, a
with a class of “ container ”, and then within that, two more
elements : “ navbar-header ” and “ navbar-collapse ”. The navbar-header div includes a button that will appear when the screen is below a certain minimum width, showing 3 horizontal lines ( a alleged “ ground beef icon ” ). The picture is rendered using pure HTML and CSS ; no prototype is required. This is the code that displays the icon, with each of the tags rendering one of the white bars:
< button type = `` button '' class = `` navbar-toggle '' data-toggle = `` collapse '' data-target = `` .navbar-collapse '' > < span class = `` icon-bar '' > < /pspan
>
<
span
class
=
"icon-bar"
>
span
>
<
span
class
=
"icon-bar"
>
span
>
button
>
It besides includes the application name, which appears in the top left. The independent seafaring menu is rendered by the
element within the second div, and includes links to Home, About, and Contact. Additional links for Register and Login are added by the _LoginPartial credit line on line 29. Below the seafaring, the main body of each page is rendered in another
, marked with the “ container ” and “ body-content ” classes. In the dim-witted default _Layout file shown here, the contents of the page are rendered by the specific View associated with the page, and then a simple
is added to the end of the
element. You can see how the built-in About page appears using this template :
The crumble navbar, with “ ground beef ” button in the top right, appears when the window drops below a certain width :
Clicking the picture reveals the menu items in a vertical drawer that slides devour from the exceed of the page :
Grids¶
One of the most popular features of Bootstrap is its grid layout arrangement. Modern web applications should avoid using the
tag for layout, alternatively restricting the use of this element to actual tabular data. rather, columns and rows can be laid out using a series of
elements and the appropriate CSS classes. There are respective advantages to this access, including the ability to adjust the layout of grids to display vertically on narrow screens, such as on phones .
Bootstrap ’ s grid layout system is based on twelve column. This total was chosen because it can be divided evenly into 1, 2, 3, or 4 columns, and column widths can vary to within 1/12th of the vertical width of the screen. To start using the grid layout system, you should begin with a container
and then add a row
, as shown here :
< div course = `` container '' > < div class = `` row '' > < /pdiv
>
div
>
following, add extra
elements for each column, and specify the number of columns that
should occupy ( out of 12 ) as separate of a CSS class starting with “ col-md- ”. For example, if you want to plainly have two columns of peer size, you would use a course of “ col-md-6 ” for each one. In this case “ mendelevium ” is unretentive for “ medium ” and refers to standard-sized desktop calculator display sizes. There are four different options you can choose from, and each will be used for higher widths unless override ( so if you want the layout to be fixed careless of screen width, you can just specify ten classes ) .
CSS Class Prefix | Device Tier | Width |
---|---|---|
col-xs- | Phones | < 768px |
col-sm- | Tablets | >= 768px |
col-md- | Desktops | >= 992px |
col-lg- | Larger Desktop Displays | >= 1200px |
When specifying two columns both with “ col-md-6 ” the resulting layout will be two columns at background resolutions, but these two columns will stack vertically when rendered on smaller devices ( or a narrower browser window on a background ), allowing users to well view contentedness without the need to scroll horizontally .
Bootstrap will always default to a single-column layout, so you only need to specify column when you want more than one column. The only time you would want to explicitly specify that a
take up all 12 columns would be to override the behavior of a larger device tier. When specifying multiple device tier classes, you may need to reset the column rendering at certain points. Adding a clearfix div that is merely visible within a certain viewport can achieve this, as shown here :
In the above model, One and Two plowshare a course in the “ doctor ” layout, while Two and Three plowshare a quarrel in the “ xs ” layout. Without the clearfix
, Two and Three are not shown correctly in the “ xs ” horizon ( note that only One, Four, and Five are shown ) :
In this example, only a individual row
was used, and Bootstrap still largely did the right thing with regard to the layout and stack of the column. typically, you should specify a row
for each horizontal row your layout requires, and of class you can nest Bootstrap grids within one another. When you do, each nested grid will occupy 100 % of the width of the component in which it is placed, which can then be subdivided using column classes .
Jumbotron¶
If you ’ ve used the nonpayment ASP.NET MVC templates in Visual Studio 2012 or 2013, you ’ ve credibly seen the Jumbotron in action. It refers to a large full-width section of a page that can be used to display a bombastic background trope, a call to action, a rotator, or alike elements. To add a jumbotron to a page, just add a
and give it a class of “ jumbotron ”, then place a container
inwardly and add your message. We can easily adjust the standard About foliate to use a jumbotron for the main headings it displays :
Buttons¶
The default option button classes and their colors are shown in the figure below .
Badges¶
Badges refer to minor, normally numeral callouts next to a navigation item. They can indicate a total of messages or notifications waiting, or the presence of updates. Specifying such badges is ampere elementary as adding a containing the text, with a class of “badge”:
Alerts¶
You may need to display some kind of notification, alert, or error message to your application ’ sulfur users. That ’ mho where the standard alarm classes come in. There are four different severity levels, with associated color schemes :
Additional Elements¶
The default subject can besides be used to present HTML tables in a nicely format dash, including support for strip views. There are labels with styles that are like to those of the buttons. You can create custom Dropdown menu that support extra style options beyond the standard HTML component, along with Navbars like the one our default starter locate is already using. If you need a advancement stripe, there are several styles to choose from, ampere well as List Groups and panels that include a deed and contentedness. Explore extra options within the standard Bootstrap Theme here :
hypertext transfer protocol : //getbootstrap.com/examples/theme/