b-collapse: change margin-left content div, when sidebar collapse. this.$root.$on('bv::collapse::state' (true - false)
See original GitHub issueHello,
I have a problem with b-collapse, when click on navbar-toggler-icon (burger icon) (v-b-toggle=“‘sidebar-fifi-toggle’”) into div b-navbar, the div sidebar collapase (b-collapse visible id=“sidebar-fifi-toggle”), but the content div remains in original position.
I needed to know how when sidebar collapse when (false), the margin-left of content div set to {margin-left: 0px;}, and when visible (true) set to {margin-left: 185px;}
if (isJustShown == false) {
css .content div: {margin-left: 0px;}
}
if (isJustShown == true) {
css .content div: {margin-left: 185px;}
}
link to code sample: https://jsfiddle.net/Lvkjn7he/1/
<div id="app">
<b-navbar toggleable="lg" type="dark" variant="dark" fixed="top">
<a href="javascript:void(0)" id="menu-toggle" v-b-toggle="'sidebar-fifi-toggle'"><span class="navbar-toggler-icon mb-1 mr-sm-1" aria-hidden="true"></span></a>
<b-navbar-brand href="index.html">brand
</b-navbar-brand>
<b-nav-form>
<b-form-input type="text" class="mb-1 mr-sm-1 mb-sm-0" placeholder="Username"></b-form-input>
<b-form-input type="password" class="mb-1 mr-sm-1 mb-sm-0" placeholder="Password"></b-form-input>
<b-button type="submit" variant="success" class="my-2 my-sm-0">Login</b-button>
</b-nav-form>
</b-navbar>
<b-collapse visible id="sidebar-fifi-toggle">
<div class="sidebar bg-white scrollable-menu">
<ul class="list-unstyled">
<li>
<a href="javascript:void(0)" role="button" data-toggle="collapse" data-target="#submenu1"><i class="fa fa-fw fa-address-card"></i> MENU 1</a>
<ul id="submenu1" class="list-unstyled collapse show">
<li><b-link :to="{name:'home'}">- Home S</b-link></li>
<li><b-link :to="{name:'about'}">- About S</b-link></li>
<li><b-link :to="{name:'contact'}">- Contact S</b-link></li>
</ul>
</li>
</ul>
</div>
</b-collapse>
<main class="content col-sm-9 offset-sm-3 col-md-10 offset-md-2 pt-3">
<h1>CONTENT - vue</h1>
</main>
</div>
new Vue({
el: '#app',
mounted() {
this.$root.$on('bv::collapse::state', (collapseId, isJustShown) => {
if (isJustShown == false) {
console.log('navbar false:', isJustShown)
}
if (isJustShown == true) {
console.log('navbar true:', isJustShown)
}
})
}
})
#app {
width: 500px;
}
.content {
margin-left: 185px;
top: 50px;
}
.sidebar {
position: fixed;
top: 51px;
bottom: 0;
left: 0;
width: 190px;
z-index: 1000;
padding: 5px;
overflow-x: hidden;
overflow-y: auto;
border-right: 1px solid #eee;
padding-left: 0;
padding-right: 0;
min-height: calc(100vh - 56px);
transition: all 0.3s;
}
when true:
when false:
any suggestions of how to do it, please
Thanks in advance
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
when sidebar collapse, change margin-left content div - Stack ...
I needed to know how when sidebar collapse (false), the margin-left of content div set to {margin-left: 0px;}, and when visible (true) set ......
Read more >Collapse | Components - BootstrapVue
Collapse. Easily toggle visibility of almost any content on your pages in a vertically collapsing container. Includes support for making accordions.
Read more >How To Create a Collapsed Sidebar - W3Schools
Click on the button to open the collapsible sidebar: ... Set the width of the sidebar to 250px and the left margin of...
Read more >Bootstrap Collapse - examples & tutorial
Responsive collapse built with Bootstrap 5. Collapse panel, vertical collapse, collapsing divs, data-toggle usage, collapse button & more.
Read more >Bootstrap 4 Collapsing Sidebar Menu on Codeply
A collapsing sidebar menu. Bootstrap 4 compatible with FontAwesome icons. When collapsed it shows only the icons. It includes logo, sub-menus, dividers with ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello, thank for reply, I took your advice, it works fine. I used @click, v-if and :class.
the result is this: https://jsfiddle.net/70wyvfc8/
when clicked on: @click=“burgerMenuSidebar” v-b-toggle=“‘sidebar-fifi-toggle’”:
when sidebar is open or show:
when sidebar is hide:
all this code works fine on one page.
but not in my separated custom components navbar, sidebar, content.
error: when sidebar is hide: not put class sidebarhide.
i use lasted version: Vue, BootstrapVue, http-vue-loader, vue-router.
I split it up several times, but I couldn’t get it to work
app.js
fifi-navbar.vue
fifi-sidebar.vue
fifi-content.vue
index.html
when clicked on: @click=“burgerMenuSidebar” v-b-toggle=“‘sidebar-fifi-toggle’”:
any suggestions of how to do it, please
Thanks in advance
Hello, I was able fix.
in fifi-navbar.vue
in fifi-content.vue
now two components communicate.
thanks for all.