I've built a bootstrap site with a nice navigation bar and layout. I want to leverage asp.net themes where I can change the look of the application.
The issue is that a lot of the classes in bootstrap aren't necessarily semantic, so it's hard to apply css to a fragment of html that has some purpose that could otherwise be identified by a semantically named class.
This is readily apparent with the bootstrap navbar which requires the navbar-light or navbar-dark classes, which control the text color of various types of elements within the navbar.
If I want one theme with dark background/light text and one theme with light background/dark text, it's hard to do natively with bootstrap because those classes need to be specified within the markup.
Do I just not use those classes, and duplicate that section of the bootstrap scss and make something that is more compatable with themes, or are there better approaches to take?
Here is an example:
<nav class="navbar navbar-expand-md navbar-dark bg-dark mb-0 flex-wrap pt-1 pb-1 shadow-none ">
<div class="d-flex flex-nowrap flex-fill minw-0">
<a class="app-link navbar-brand text-truncate mr-auto mt-auto mb-auto d-flex align-items-center" href="../../../"/>
<img class="app-logo mt-auto mb-auto" src="../../../App_Themes/IHClean/img/app/applogo.svg">
<span class="text-truncate font-weight-normal">Non-semantic Css</span>
</a>
<button class="navbar-toggler my-1 ml-auto bg-dark-heavy" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"/>
</button>
</div>
<div class="collapse navbar-collapse flex-wrap d-md-inline-flex justify-content-end">
<div class="d-md-inline-flex">
<ul class="navbar-nav nav">
<li class="active nav-item">
Home
</li>
<li class="nav-item">
<a href="../../../Samples" class="nav-link icon-mmnu-info">Samples
<span class="badge badge-balloon badge-light">
<span class="d-xs-inline d-sm-none text-primary">XS</span>
<span class="d-none d-md-none d-sm-inline text-success">SM</span>
<span class="d-none d-md-inline d-lg-none text-danger">MD</span>
<span class="d-none d-lg-inline d-xl-none text-warning">LG</span>
<span class="d-none d-xl-inline text-dark">XL</span>
</span>
</a>
</li>
</ul>
</div>
<div class="d-md-inline-flex">
</div>
</div>
</nav>
The navbar-dark class requires a light background color or text won't show up. If I want to be able to use ASP.Net Themes in a web forms app, I am limited to how I can apply theme colors because of the use of navbar-dark. I can't invert the dark on light easily and still retain semantics. Perhaps I just have to forgo the sematics and override the navbar dark variables.
Related
I have a problem by adding the Sticky-top function to a navbar in a Django proyect. The navbar is responsive and can be desplegated by clicking a button, but I want it to be always present in the top when te user scroll down.
I'm using the next code:
<div id="navBar"><!--Barra de navegaciĆ³n-->
<nav class="navbar navbar-expand-lg navbar-light sticky-top" id="mainNavbar" >
<div class="container">
<a class="navbar-brand"></a>
<a class="navbar-brand" ></a>
<button class="navbar-toggler navbar-toggler-right collapsed" type="button" id="collapse-button"data-toggle="collapse" data-target="#navbarContent" aria-controls="navbarContent"
aria-expanded="false" aria-label="Toggle navigation">
<span>Menu</span>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarContent">
<ul class="navbar-nav ml-auto">
<li class="nav-link" >
Inicio
</li>
<li class="nav-link">
Contacto
</li>
</ul>
</div>
</div>
</nav>
</div>
The docs do not explicitly declare this but if you look at all the samples they only ever nest the nav.navbar inside a div.container. I was only able to get your code to work properly after removing the #navBar wrapper.
Not recommended:
It will also work if you apply the class sticky-top directly to the #navBar wrapper instead of the nav.navbar but that seems to go against the intended usage and therefore it may not work in every browser.
How do you solve this issue where the navbar menu doesn't reveal downwards on medium sizes? It works fine on other screen sizes. I attached an Image here. I don't know what causes this, please help.
[ FIXED ]
The md in col-md apparently corresponded to its column on that particular breaking point. I thought it simply indicated what breaking point would cause it to collapse into seperate rows!
Removing the col-md-4 and making it col-lg-4 fixed the issue. Thank you, Overthane!
<nav class="navbar navbar-expand-lg navbar-light bg-white">
<div class="brand-column col-md-4">
<div class="navbar-brand">
<span>Plug</span>
</div>
</div>
<button class="navbar-toggler ml-auto" type="button" data-toggle="collapse" data-target="#navbarContent">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse col-md-4" id="navbarContent">
<ul class="navbar-nav mx-auto d-flex align-items-center text-nowrap text-center">
<li class="nav-item active mx-1">
<a class="nav-link text-header">Home</a>
</li>
<li class="nav-item mx-1">
<a class="nav-link text-header">Solutions</a>
</li>
<li class="nav-item mx-1">
<a class="nav-link text-header">About Us</a>
</li>
<li class="nav-item mx-1">
<a class="btn btn-success btn-sm px-3 rounded-pill"> Login </a>
</li>
</ul>
</div>
</nav>
That's happening because the class .col-md-4 makes the .navbar-collapse element into a column with a size of 4 on medium screens (md). You should be able to achieve the desired effect by changing that element's classes to the following:
<div class="collapse navbar-collapse col-md-12 col-lg-4" id="navbarContent">
I have to create a layout in which a content grid has to be on the full remaining page, but the layout has also a navigation bar.
In order to do this I decided to place the navigation bar in a flex container and the content in a row with height 100%. I need the content to fill the rest of the remaining space. The menu is dynamic so I can not know how the height of the navigation bar is.
However on smaller screens the navigation bar does not resize correctly. If the menu is expanded the menu is overlayed with the content.
<div class="container-fluid h-100 d-flex flex-column">
<nav class="navbar navbar-expand-sm s-navbar">
...
</nav>
<div class="row h-100">
...// content presented here
</div>
</div>
You can see it here
https://jsfiddle.net/ej9fd368/8/ that the last menu item is cut because of the yellow content.
My requirement is that the content should fill the rest of the page.
Instead of using h-100 on the yellow content area, add an extra CSS class to make it flex-grow:1 in height...
.flex-fill {
flex:1 1 auto;
}
https://www.codeply.com/go/xBAMfbHqbN
<div class="container-fluid h-100 d-flex flex-column">
<nav class="navbar navbar-expand-sm s-navbar">
<a class="brand navbar-brand" href="/">Brand</a>
<button class="navbar-toggler s-btn-hamburger order-first s-color-icons" aria-expanded="true" aria-controls="navbar-test" aria-label="Toggle navigation" type="button" data-target="#navbar-test" data-toggle="collapse">
<span class="navbar-toggler-icon k-icon k-icon-md k-i-hamburger"></span>
</button>
<div class="navbar-collapse s-menu-content collapse show" id="navbar-test">
<ul class="navbar-nav mr-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" id="dropdown1" aria-expanded="false" aria-haspopup="true" data-toggle="dropdown">Menu Item</a>
<div class="dropdown-menu" aria-labelledby="dropdown1">
<a class="dropdown-item" href="/Device">Sub menu</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="/Test">Test</a>
</li>
</ul>
</div>
</nav>
<div class="row flex-fill">
<main class="col" style="background-color: yellow"></main>
</div>
</div>
Note: The flex-fill utility class will be included in the next Bootstrap 4.1 release:
https://github.com/twbs/bootstrap/commit/2137d61eacbd962ea41e16a492da8b1d1597d3d9
(Updated Bootstrap 4.1 demo)
Related question: Bootstrap 4: How to make the row stretch remaining height?
I have spent already several hours trying to correctly position several elements in a fixed bootstrap navbar, but I do not manage to have exactly what I would like. This is what I have so far:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header pull-left">
<a class="navbar-brand" href="http://www.aprentiko.com">brand</a>
<p class="navbar-text">title of the page</p>
</div>
<div class="collapse navbar-collapse navbar-right">
<ul class="nav navbar-nav navbar-right">
<li></span></li>
<li><span class="glyphicon glyphicon-cog"></span></li>
<li></span></li>
</ul>
</div>
<div class="navbar-header pull-right">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<ul class="nav navbar-nav">
<li><span id="audioInPause" class="glyphicon glyphicon-play"></span></li>
</ul>
</div>
</div>
</nav>
The problems I have are the following:
I would like to position the "title of the page" element in the middle of the screen, but it always stays in the left, next to the brand.
The audioControl item should be independent of the other icons in the right side (i.e. it should not collapse when the viewport becomes too small. I achieved the "not collapsing" part, but when the icons collapse I get a) the play button always goes in a second row, b) clicking on the collapsed button activates the play button, instead of opening the menu to select one of the collapsed items.
I created a jsfiddle at https://jsfiddle.net/cwx1wvo7
I can answer the first one quickly, but I don't know if it will work with collapse, you can play around.
I agree with the comment above about by MattD. As a twist, partition your nav using col-lg-xx col-md-xx etc then use text-center
As an example to give you and idea,
<div class="navbar-header pull-left col-lg-10 col-md-9">
<a class="navbar-brand" href="http://www.aprentiko.com">brand
<p class="text-center navbar-text">title of the page</p>
</a>
</div>
<div class="collapse navbar-collapse navbar-right col-lg-2 col-md-3">
in fact, u should take a look at the bootstap.css to have an idea of the classes used to code elements.
the ms-md-auto move ur elements to the right:
.ms-md-auto {
margin-left: auto !important;
}
<ul class="navbar-nav ms-md-auto mb-2 mb-lg-0" >
I have a Bootstrap nav-bar, which collapses into a button, totally default.
In my nav-bar, I have a bunch of images, instead of text links. When the bar is collapsed, I would like these pictures to be smaller.
Is there any way to style my way out of this?
Can I give it another menu to use, when it's collapsed?
Example code (default Bootstrap):
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#FlagMenu">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Select plant</a>
</div>
<div class="collapse navbar-collapse" id="FlagMenu">
<ul class="nav navbar-nav">
<li>
<img src="~/Content/imgs/Flag_Dansk.png" />
</li>
<li>
<img src="~/Content/imgs/Flag_Tjekkisk.png" />
</li>
<li>
<img src="~/Content/imgs/Flag_Mexikansk.png" />
</li>
<li>
<img src="~/Content/imgs/Flag_Ungarsk.png" />
</li>
<li>
<img src="~/Content/imgs/Flag_China.png" />
</li>
</ul>
</div>
</div>
</nav>
You can overwrite parts of media queries styles of bootstrap by adding your own class to html-structure where you define styles (width, height, etc.) for the images.