The method of making a vertical navigation bar in Bootstrap is as follows: 1. Use the flex-column class to change the default horizontal navigation to vertical arrangement, with the structure code
<ul class="nav flex-column"> <li class="nav-item"> <a class="nav-link" href="#">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="#">About</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Contact</a> </li> </ul>
-
nav
is the basic class that controls the overall style; -
flex-column
changes the layout from horizontal to vertical; - Each
nav-item
is a menu item; -
nav-link
is the link style.
What is written in this way is a simple vertical navigation bar with no background color or spacing, which is suitable for use in the sidebar area for other layouts.

Add styles and spacing
The default vertical navigation looks a bit compact, and you can make the appearance look better in a few ways:
- Add
p-3
orpy-2
to.nav
to increase the margin; - Add
mb-2
to eachnav-link
so that there is a gap between the entries; - Use Bootstrap's color classes, such as
bg-light
ortext-dark
, to adjust the background and text colors;
Example:

<ul class="nav flex-column bg-light p-3"> <li class="nav-item mb-2"> <a class="nav-link text-dark" href="#">Home</a> </li> <li class="nav-item mb-2"> <a class="nav-link text-dark" href="#">About</a> </li> <li class="nav-item"> <a class="nav-link text-dark" href="#">Contact</a> </li> </ul>
The navigation made in this way is closer to the style requirements in actual projects and looks more professional.
Optional feature: Add icon or submenu
If you want to do more, you can consider adding icons or lower menus.
- Icons can be used with FontAwesome or Bootstrap Icons;
- The submenu can be implemented with nested
ul
, but you need to write a little CSS or JS control by yourself to expand and close; - If it is just a static page, it is recommended to be simpler and not to make too complicated functions;
To give a small example (without interaction):
<ul class="nav flex-column"> <li class="nav-item"> <a class="nav-link" href="#"><i class="bi bi-house"></i> Home</a> </li> <li class="nav-item"> <a class="nav-link" href="#"><i class="bi bi-info-circle"></i> About us</a> </li> </ul>
Here we use the icon library of Bootstrap Icons, and the visual effect will be clearer and more intuitive after adding the icon.
Basically that's it. As long as you master the basic structure and add styles and functions according to project requirements, you can create a practical vertical navigation bar.
The above is the detailed content of How to make a vertical navbar in Bootstrap?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

The advantage of creating forms with Bootstrap is that it provides a consistent and responsive design, saving time, and ensuring cross-device compatibility. 1) Basic forms are simple to use, such as form-control and btn classes. 2) Vertical forms achieve a more structured layout through grid classes (such as col-sm-2 and col-sm-10).

TheBootstrapGridSystemcanbeoptimizedforbetteraccessibility.1)UsesemanticHTMLtagslikeandinsteadofgenericelements.2)ImplementARIAattributestoenhancescreenreaderfunctionality.3)ManagefocusorderlogicallywithBootstrap'sorderclasses.4)Useutilityclassesforp

BootstrapGridSystemisbetterforquick,simpleprojects;Flexboxisidealforcustomizationandcontrol.1)Bootstrapiseasiertouseandfastertoimplement.2)Flexboxoffersmorecustomizationandflexibility.3)Flexboxcanbemoreperformant,butthedifferenceisusuallyminor.4)Boot

Bootstrapformscanleadtoerrorslikemisusingthegridsystem,improperformcontrols,validationissues,neglectingcustomCSS,accessibility,andperformance.Toavoidthese:1)Usecolumnclasseslikecol-sm-orcol-md-forresponsiveness;2)Wrapinputfieldsin.form-groupforproper

Bootstrap'sGridSystemisessentialforcreatingresponsive,modernwebsites.1)Itusesa12-columnlayoutforflexiblecontentdisplay.2)Columnsaredefinedwithinrowsinsideacontainer,withwidthslikecol-6forhalf-width.3)Responsivenessisachievedusingclasseslikecol-sm-6fo

Bootstrap'sGridSystemhelpsinbuildingresponsivelayoutsbyofferingflexibilityandeaseofuse.1)Itallowsquickcreationofadaptablelayoutsacrossdevices.2)Advancedfeatureslikenestedrowsenablecomplexdesigns.3)Itencouragesaresponsivedesignphilosophy,enhancingcont

Bootstrapformtemplatesareidealforquickwinsduetotheirsimplicity,flexibility,andeaseofcustomization.1)UseacleanlayoutwithBootstrap'sform-groupandform-controlclassesfororganizedandconsistentstyling.2)Customizecolors,sizes,andlayouttofityourbrandbyoverri

BootstrapGridSystemisapowerfultoolforcreatingresponsive,mobile-firstlayouts.1)Itusesa12-columngridwithclasseslike'row'and'col'forstructuringcontent.2)Breakpointslike'col-sm-6'or'col-md-4'allowlayoutstoadapttodifferentscreensizes.3)Nestinggridsandusin
