Raja Anbazhagan Raja Anbazhagan - 6 months ago 410
CSS Question

how to make md-sidenav push content to the right instead of overlapping it?

Is there any way I can make the side nav sticky so that when the side nav opens, it pushes the content of the page to the right instead of just overlapping it like https://inbox.google.com/ ?

Here is the plunker link of my sample work

<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Angular Material style sheet -->
<link rel="stylesheet"
href="https://ajax.googleapis.com/ajax/libs/angular_material/1.1.0-rc2/angular-material.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="css/main.css">
</head>
<body ng-app="BlankApp" layout="column" ng-cloak ng-controller="AppCtrl">
<md-toolbar class="md-whiteframe-7dp" layout="row">
<md-button class="menu" ng-click="toggleSidenav();"><i class="material-icons">menu</i></md-button>
<h3>Hello Toolbar</h3>
</md-toolbar>

<md-content id="body-part" flex layout="row" layout-fill>
<md-sidenav md-disable-backdrop class="md-whiteframe-7dp" md-component-id="left-side-nav"
flex style="background: cyan">
<span>Hello Nav..!!</span>
</md-sidenav>
<div flex style="padding: 10px;overflow-y: scroll; background: darkcyan">
<span>Hello Content...!</span><br>
</div>
</md-content>


<!-- Angular Material requires Angular.js Libraries -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-aria.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-messages.min.js"></script>

<!-- Angular Material Library -->
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/1.1.0-rc2/angular-material.min.js"></script>

<!-- Your application bootstrap -->
<script src="js/script.js"></script>
</body>
</html>

Answer

You need to add a relative position to the sidenav css styling:

From your Plunker:

md-sidenav, md-sidenav.md-locked-open, md-sidenav.md-closed.md-locked-open-add-active {
    min-width: 200px !important;
    width: 50vw !important;
    max-width: 200px !important;
    position:relative;
}

https://plnkr.co/edit/cheYKMT2Mjy7Bvqv62hI?p=preview