Docsify: how to hide the sidebar on small screen

Created on 16 May 2018  路  8Comments  路  Source: docsifyjs/docsify

Hi, i want to hide the sidebar.
below is what i do?

  <style>
    aside {
      display: none;
    }
    .sidebar-toggle {
      display: none;
    }
  </style>
</head>
<body class="close">

it works ok on big screen?

on a little screen

2018-05-16 8 15 21

look the picture above, there is some space on the left.

Can we hava a option to specify if there sidebar should be renderred?

Most helpful comment

I found the CSS to hide and show the sidebar to be backwards for desktop and mobile
I couldn't find a good solution to keep the sidebar closed and open it with JS

index.html

  <body class="no-sidebar">

CSS

body.no-sidebar .sidebar,
body.no-sidebar .sidebar-toggle {
    display: none !important;
}

body.no-sidebar .content {
    left: 0px !important;
}

JS

// As a docsify plugin
  hook.doneEach(() => {
    const file = vm.route.file;
    if (!file.match(/^[^/]*\.md$/)) {
      dom.classList.remove('no-sidebar');
    } else {
      dom.classList.add('no-sidebar');
    }
  });

I only wanted the sidebar for routes in a directory

All 8 comments

the white space is not sidebar

@Xcorpio can you share with us your repo's URL ?

First of all, fix the "readme" error on your root., I mean https://github.com/ojlm/ojlm/tree/master/docs does not have a "readme.md" and that file is required.

@SidVal as you asked. You can hava a look at http://ojlm.tech/#/2018/01-01
image

This is on mobile chrome.

I found the CSS to hide and show the sidebar to be backwards for desktop and mobile
I couldn't find a good solution to keep the sidebar closed and open it with JS

index.html

  <body class="no-sidebar">

CSS

body.no-sidebar .sidebar,
body.no-sidebar .sidebar-toggle {
    display: none !important;
}

body.no-sidebar .content {
    left: 0px !important;
}

JS

// As a docsify plugin
  hook.doneEach(() => {
    const file = vm.route.file;
    if (!file.match(/^[^/]*\.md$/)) {
      dom.classList.remove('no-sidebar');
    } else {
      dom.classList.add('no-sidebar');
    }
  });

I only wanted the sidebar for routes in a directory

thanks, no-sidebar works.

@dmed256's answer is awesome. If only to hide sidebar in homepage, just css is enough.

body[data-page="main.md"] .sidebar,
body[data-page="main.md"] .sidebar-toggle {
  display: none !important;
}
body[data-page="main.md"] .content {
  left: 0px !important;
}
Was this page helpful?
0 / 5 - 0 ratings