1
\$\begingroup\$

I am creating a static site in HTML and CSS. I'm using Sass for the CSS. The whole repository can be found here on Bitbucket.

I wanted feedback on the way I've done the sidebar. The code is split across many files, so not sure if I should add them all or not.

CODE

_variables.scss file has this:

$sidebar-width: 20%;
$sidebar-width-mobile: 70%;
$sidebar-width-tablet: 40%;
$sidebar-width-tablet-l: 30%;
$dark-grey: #353535;
$light-grey: #d9d9d9;
$bejebeje-red: #d11c21;

_sidebar.scss has this:

#site-wrapper {
  padding-left: 0;
  transition: all 0.5s ease;
  height: 100%;

  nav {
    background-color: $dark-grey;
    z-index: 1000;
    position: fixed;
    left: $sidebar-width;
    width: 0;
    height: 100%;
    margin-left: -$sidebar-width;
    overflow-y: auto;
    transition: all 0.5s ease;

    .stitch {
      height: 100%;
      margin: 0 5px 0 5px;
      border-left: 2px dashed lighten($dark-grey, 30%);
      border-right: 2px dashed lighten($dark-grey, 30%);

      .logo-wrap {
        margin: 0 auto;
        background-color: $bejebeje-red;
        width: 160px;
        overflow: hidden;

        .stitch {
          margin-bottom: 5px;
          border-color: $dark-grey;
          border-bottom: 2px dashed $dark-grey;
          overflow: hidden;

          a {
            display: block;

            .logo {
              height: 100px;
              width: 82px;
              background: url('../images/logo.svg') no-repeat 0 0 $bejebeje-red;
              background-size: 82px 100px;
              text-indent: -999999px;
              justify-content: center;
              margin: 0 auto;
              margin-top: 30px;
              margin-bottom: 30px;
            }
          }
        }
      }
    }
  }

  main {
    background-color: lighten($light-grey, 10%);
    height: 100%;

    .fa {
      font-size: 2rem;
      cursor: pointer;
    }
  }

  &.visible {
    padding-left: $sidebar-width-mobile;

    nav {
      width: $sidebar-width-mobile;
      left: $sidebar-width-mobile;
      margin-left: -$sidebar-width-mobile;
    }

    main {
      width: 100%;
      position: absolute;
      padding: 15px;
      position: absolute;
      margin-right: -$sidebar-width-mobile;
      height: 100%;
    }
  }
}

@media (min-width: 540px) {
  body #site-wrapper {
    padding-left: 0;
    height: 100%;

    nav {
      background-color: palegreen;
      width: 0;
    }

    main {
      padding: 20px;
      position: relative;
      height: 100%;
    }

    &.visible {
      padding-left: $sidebar-width-tablet;

      nav {
        width: $sidebar-width-tablet;
      }

      main {
        position: relative;
        margin-right: 0;
      }
    }
  }
}

@media (min-width: 960px) {
  body #site-wrapper {
    padding-left: 0;
    height: 100%;

    nav {
      background-color: steelblue;
      width: 0;
    }

    main {
      padding: 20px;
      position: relative;
      height: 100%;
    }

    &.visible {
      padding-left: $sidebar-width-tablet-l;

      nav {
        width: $sidebar-width-tablet-l;
      }

      main {
        position: relative;
        margin-right: 0;
      }
    }
  }
}

@media (min-width: 1140px) {
  body #site-wrapper {
    padding-left: 0;
    height: 100%;

    nav {
      background-color: steelblue;
      width: 0;
    }

    main {
      padding: 20px;
      position: relative;
      height: 100%;
    }

    &.visible {
      padding-left: $sidebar-width;

      nav {
        width: $sidebar-width;
      }

      main {
        position: relative;
        margin-right: 0;
      }
    }
  }
}

structure.scss has this:

html {
  height: 100%;
}

body {
  overflow-x: hidden;
  height: 100%;

  #site-wrapper {
    padding-left: 0;
    transition: all 0.5s ease;
    height: 100%;
  }
}

Finally, index.html has this:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Bejebeje</title>
  <link rel="stylesheet" href="css/styles.css" type="text/css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>

<body>
  <div id="site-wrapper" class="">
    <nav>
      <div class="stitch">
        <div class="logo-wrap">
          <div class="stitch">
            <a href="index.html">
              <h1 class="logo">Bejebeje</h1>
            </a>
          </div>
        </div>
      </div>
    </nav>

    <main>
      <div class="container-fluid">
        <h1>Content</h1>
        <a href="#menu-toggle" class="btn btn-secondary" id="menu-toggle">Toggle Sidebar</a>
      </div>
    </main>
  </div>
  <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
    crossorigin="anonymous"></script>
  <script src="../node_modules/tether/dist/js/tether.min.js"></script>
  <script src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
  <script>
    $("#menu-toggle").click(function (e) {
      e.preventDefault();
      $("#site-wrapper").toggleClass("visible");
    });
  </script>
</body>

</html>

But basically, the way I've done it feels pretty messy to me, I feel like there's an easier way.

I've split the Sass across various files in Sass\modules.

Here's a Codepen too.

\$\endgroup\$
  • \$\begingroup\$ To make the question selfcontained, please add all code that is relevant for the review. \$\endgroup\$ – insertusernamehere Oct 20 '17 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.