Put fixed navbar and sidebar in all components of Angular app - html

So, I am new to angular and building a new angular app which will consist of multiple components and I want the navbar and sidebar to be fixed on all components of my app.
I built navbar and sidebar as separate components. I want the navbar and sidebar to be like this, with the app content(all the component content) being in the white part of the screen:
I know the navbar can be easily imported with html like <navbarComponent><navbarComponent>, but the sidebar is a bit problematic to me since I want the app-content to be on the right of the sidebar component, so the only solution I know is to make a container in css like this:
random-component-html:
<app-navigation-bar></app-navigation-bar>
<div class="d-flex container1">
<div class="al-left">
<app-sidenav-bar></app-sidenav-bar>
</div>
<div class="al-right">
<div class="container">
<h2>Apps:</h2>
<mat-nav-list>
<mat-list-item *ngFor="let app of apps" (click)="redirect(app)">
<button mat-icon-button> {{app.name}}
</button>
</mat-list-item>
</mat-nav-list>
</div>
</div>
</div>
random-component-css:
.container1{
width: 100%;
}
.al-left{
float: left;
max-width: 15vw;
}
.al-right{
float: right;
max-width: 85vw;
}
but I feel that there must be an easier way to do this. Does anybody know a solution?

You can route all your other components within this white block
Lets say:
<app-navigation-bar></app-navigation-bar>
<div class="d-flex container1">
<div class="al-left">
<app-sidenav-bar></app-sidenav-bar>
</div>
<div class="al-right">
<div class="container">
<router-outlet></router-outlet>
</div>
</div>
</div>

You can add your header(navbar), sidebar, footer component in your app.component.html
<app-header></app-header>
<app-sidebar></app-sidebar>
<app-footer></app-footer>
<router-outlet></router-outlet>
You can also add footer as well as shown in above example.
And header sidebar & footer will remain in all the rest of the components.

Related

Bootstrap - Fixed Sidebar in body

Im building a react website and am using Bootstrap 4. On one of my page in the content body I have a two column layout. The left side is a sidebar and on the right is a long column of content. When scrolling I want to keep the left sidebar on top.
Here is a picture for illustration:
My current code works, however when scrolling down the sidebar gets fixed/positioned at the center instead of the top. It looks like it's being aligned as if the header is still above it. Here is my current code:
<div className="header-wrap">
//Header Here
</div>
<div className="container">
<div className="row">
<div className="col-3 position-fixed" id="sticky-sidebar">
//Sidebar here
</div>
<div className="col offset-3" id="main">
//body here
</div>
</div>
</div>
<div className="footer-wrap">
//Footer Here
</div>
My goal is as you scroll, the header leaves the screen (which it already does) the sidebar gets positioned to the top.
for example
try the code
#sticky-sidebar{ position: sticky; top: 0;}
I'm leaving a few resources
https://www.w3schools.com/howto/howto_js_navbar_sticky.asp
https://www.w3schools.com/howto/howto_css_image_sticky.asp

large primeng components butcher css in flexbox

I have a simple Angular application, with a Navbar on top, a footer on the bottom and some content inbetween
<div id="app">
<app-navbar></app-navbar>
<div id="content">
<router-outlet></router-outlet>
</div>
<div id="footer">
<app-footer></app-footer>
</div>
</div>
html,
body {
height: 100%;
}
#app {
height: 100%;
display: flex;
flex-direction: column;
}
#content {
flex: 1;
}
in the content section, I have a tabView wrapped into a row/col setup, like this:
<div class="row ">
<div class="col-md-12">
Lorem ipsum works even with very large texts
</div>
</div>
The styling works perfectly, in that when the content section gets larger than the default size of the app, the footer moves down however much it needs.
However, if instead of putting plain HTML/ plain text I place any Primeng components (here: TabView) that are larger than the standard screen size/ standard position of the footer, the styling breaks and the content gets placed on top of the footer, instead of pushing the footer down.
<div class="col-md-12"> <-- ENLARGING THIS WORKS
<p-tabView orientation="top" [activeIndex]="tabIndex" (onChange)="handleChange($event)" class="order-form"
styleClass="tabview-compo-workbench height-test"> <-- ENLARGING THIS CAUSES THE ISSUE
<p-tabPanel class="tabview-panel-workbench" styleClass="tabview-compo-workbench">
<ng-template pTemplate="header">First Tab</ng-template>
<ng-template pTemplate="content">
some html content
</ng-template>
</p-tabPanel>
<p-tabPanel>
<ng-template pTemplate="header">Second Tab</ng-template>
<ng-template pTemplate="content">
some html content
</ng-template>
</p-tabPanel>
</p-tabView>
</div>
Is there any way to fix this issue? Worst case programmatically.

Angular 6: Mat-card Make Page Content Scrollable w/o using fixed prop

I have a top nav, side nav and the main content of the page. On click, the tabs on the side nav should bring the div associated with the tab to the top of the page (This is a different issue i am facing as scrollTop method from JS isn't working, but I am able to use scrollIntoView() for now to get something going)
template
<mat-card class="main-card">
<mat-card-title>Some title</mat-card-title>
<mat-card-content class="main-content">
<div class="div1">Div1 content</div>
<div class="div2">Div2 content</div>
<div class="div3">Div2 content</div>
</mat-card-content>
</mat-card>
CSS
.main-card {
overflow: auto;
height: 700px;
}
.main-content {
height: 1000px;
overflow: auto;
}
sidenav items
<div class="side-nav">
<div class="mat-list-item" (click)="handleElemScroll(div1)">
<span>Div1</span>
</div>
<div class="mat-list-item" (click)="handleElemScroll(div2)">
<span>Div2</span>
</div>
<div class="mat-list-item" (click)="handleElemScroll(div1)">
<span>Div2</span>
</div>
</div>
on the main card, I am unable to add the height prop to, even if I use !important. I've run into this issue with a few other times using angular-material. I am forcing a scroll, but mid way through the scroll, the entire page begins to scroll. Even though the height of my mat-card-content is set to be larger than the mat-card itself.
A few questions if anyone can guide me
1. Why does my entire page begins to scroll mid way?
2. Without making my side and top nav stick, how can I implement a scroll? Is my idea of using overflow, and making the inner container height larger than its parent container the correct idea here?
Thanks for any help

Semantic UI Sidebar pushes elements outside of screen width

I'm not sure if I'm doing something wrong or if this is the intended result but the I'm using semantic ui's sidebar and it pushes everything past the max screen width. Am I missing something here?
<div class="ui bottom attached segment pushable">
<div class="ui left vertical menu visible thin attached inverted sidebar">
<a class="item">
Item 1
</a>
<a class="item">
Item 2
</a>
<a class="item">
Item 3
</a>
</div>
<div class="pusher">
<div id="search-bar">
<div class="ui fluid action input">
<input placeholder="Search..">
<div class="ui green button"> Search </div>
</div>
</div>
<h3 class="ui block header">
Item
</h3>
</div>
</div>
https://jsfiddle.net/kour6d1x/
If you don't want the content "pushed" for the Semantic UI sidebars you should use the .overlay class on it - relevant demos
Like the class name suggests, it will overlay the sidebar rather than pushing the content along with it.
Add overlay class to the <div class="ui left vertical menu visible thin attached inverted sidebar"> element.
JSfiddle
I have used below css to reduce thr width of pusher when sidebar is open. In below code 58px is the width of sidebar
.sidebar.visible + .pusher{
margin-right: 58px;
}
Custom CSS subtracting the width of the sidebar would do the trick:
.sidebar.visible + .pusher {
width: calc(100% - 260px);
}

Pin bootstrap col-md-2 div to the top

I am trying to have my bootstrap 3.0 layout pin the content of the right column to the top, thus staying in place as the main content scrolls on. I have arrived at the following code, which blows up as I re-size the browser. Is there a way to do this?
<div class="col-md-10>main content</div>
<div class="col-md-2 container" style="padding: 15px 0px 10px 23px; position: fixed; right: 20px; top:75px">
Right column, stuck to the top
</div>
I am not really (engineer learning these techniques) a bootstrap or CSS guy, so if bootstrap doesn't support this - that is valuable information for me as well.
You can use affix on the content inside the right column..
<div class="col-md-10>main content</div>
<div class="col-md-2">
<div class="affix">..</div>
</div>
Here's an example Bootply that you may find useful: http://bootply.com/104413
Demo
You can do this by using the affix class.
<div class="well col-span-4" data-spy="affix">
<div class="btn btn-large btn-danger col-span-12">This is fixed</div>
</div>
Animation