Bootstrap 4 Navbar and content fill height flexbox - css

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?

Related

Bootstrap 4.1, vertical navbar breakpoint not working

I have a website with a horizontal navbar, works fine. At the appropriate breakpoints it collapses and you open it via the hamburger button.
Underneath I have a bootstrap row:
<div class="row">
<div class="col-xl-2 px-0">
<div class="container-fluid">
<div class="container show-not-on-mobile text-center pt-5"> <h5>Paintings</h5></div>
<nav class="navbar navbar-expand-xl navbar-light navbar-custom">
<div class="container mb-0 px-0 show-not-on-desktop">
<a class="navbar-brand" href="/paintings">Paintings</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#mnav" aria-controls="mnav" aria-expanded="false" aria-label="Toggle navigation">
<span class="fancy-toggler navbar-toggler-icon"></span>
</button>
</div>
<div class="container mb-0 px-0">
<div class="collapse navbar-collapse" id="malereinav">
<ul class="navbar-nav mr-auto mx-auto flex-column">
<li class="nav-item">
<a class="nav-link active rounded" title="Movement" href="/paintings-movement">
Movement
</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
</div>
<div class="col-xl-10">
Gallery Content shown with #Columns
</div>
</div>
Everything works fine, except this breakpoint:
#media screen and (min-width:992px) and (max-width: 1280.98px){
#columns[data-columns]::before {
content: '3 .col-lg-4';
}
}
At this breakpoint nothing happens with this navbar:
neither the navbar is displayed horizontally nor vertically.
Also no mobile version with hamburger is displayed.
No matter if I use navbar-expand-xl or navbar-expand-lg or navbar-expand-md ...
Maybe someone has an idea, I would be very happy.

How can I put the navigation above the main layout container?

I am new with R, and I am trying to get a custom layout. I have my CSS.
Below is my code:
ui <- fluidPage(
theme="www/style.css" ,
suppressDependencies("bootstrap"),
tags$head(includeCSS("www/styles.css")),
HTML('<nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">
<div id="wrapper-top">
<ul class="navbar-nav ml-auto">
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<li class="nav-item active mr-3">
<a class="nav-link acces" href="/">Link</a>
</li>
</div>
</ul>
</div>
</nav>'),
tags$footer( HTML("<footer class='sticky-footer' role='footer'>
<div class='container my-auto'>
<div class='copyright text-center my-auto'>
<span>©
2021
<a aria-label='' href=''>My footer</a>
</span>
</div>
</div>
</footer>")),
This gives me an output like this:
What I trying to achieve is to get the navigation below body tag currently it's all wrapped with this container-fluid class. And also I am trying to get the footer at the bottom of the page
Example:
Is there anyone that can help me with this? Thank you all

Bootstrap NavBar collapsing in a different position

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">

ASP.Net bootstrap and App_Themes

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.

How to get jumbotron colour to also cover navbar

I'm trying to get a picture (below I've tested with a single background color) to cover the navbar aswell as the showcase/jumbotron. However I can't get it to cover both correctly and the navbar is left untouched - even if I create a div that surround the navbar and jumbotron and assign a background picture to this.
Additionally when I try a picture it is stretched in a rather random way across the showcase, how do I get this to cover the elements correctly ?(image size is 1400x693 svg).
<header class="nav-header">
<nav class="navbar navbar-expand-md navbar-light bg-light">
<div class="container">
<span class="navbar-brand"><i>Logo</i></span>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-collapse"
aria-controls="navbar-collapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav ml-auto">
<li class="nav-item"><a class="nav-link" href="#">How it works</a></li>
</ul><!--//nav-->
<ul class="nav navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#">My Profile</a>
</li>
<li class="nav-item">
<a class="btn btn-outline-success" href="#">Log out</a>
</li>
</ul>
</div>
</div>
</nav><!--//header-->
</header>
<section>
<div class="showcase">
<div class="container">
<div class="jumbotron jumbotron-fluid showcase-content text-white">
<div class="row">
<div class="col-lg-6">
<h2 class="display-4">Some title.</h2>
<p class="lead">Some additional showcase text.</p>
<p>
<a class="btn btn-secondary text-white " href="#">Get Started -></a>
</p>
</div>
<div class="col-lg-6">
<image></image>
</div>
</div>
</div>
</div><!--//container-->
</div>
</section><!--//promo-->
Css
.showcase {
background-color: red;
background-size: cover;
}
.nav-header {
background-color: transparent;
}
.showcase-content {
background-color: transparent;
}
Codepen:
https://codepen.io/anon/pen/vjqvEE
The issue was having bg-light within the navbar which was overriding assigning the colour to the navbar too.

Resources