Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body>
  <header class="container header">
    <div>
      <a href="index.html"><img src="#" alt="Описание"></a>
    </div>
  </header>
  <div class="container main">
    <div class="row">
      <div class="col col__aside">

        <button type="button" id="nav-toggle" class="show">
          Меню
        </button>

        <nav id="accordion" class="accordion">
          <div class="accordion-item">
            <div class="accordion-item-header">
              Пункт one
            </div>
            <div class="accordion-item-content">
              <ul class="accordion-subitems">
                <li class="accordion-subitem">
                  <a href="#">Подпункт one</a>
                </li>
                <li class="accordion-subitem">
                  <a href="#">Подпункт two</a>
                </li>
                <li class="accordion-subitem">
                  <a href="#">Подпункт three</a>
                </li>
                <li class="accordion-subitem">
                  <a href="#">Подпункт four</a>
                </li>
              </ul>
            </div>
          </div>
          <div class="accordion-item">
            <div class="accordion-item-header">
              Пункт two
            </div>
            <div class="accordion-item-content">
              <ul class="accordion-subitems">
                <li class="accordion-subitem">
                  <a href="#">Подпункт one</a>
                </li>
                <li class="accordion-subitem">
                  <a href="#">Подпункт two</a>
                </li>
                <li class="accordion-subitem">
                  <a href="#">Подпункт three</a>
                </li>
                <li class="accordion-subitem">
                  <a href="#">Подпункт four</a>
                </li>
              </ul>
            </div>
          </div>
          <div class="accordion-item">
            <div class="accordion-item-header">
              Пункт three
            </div>
            <div class="accordion-item-content">
              <ul class="accordion-subitems">
                <li class="accordion-subitem">
                  <a href="#">Подпункт one</a>
                </li>
                <li class="accordion-subitem">
                  <a href="#">Подпункт two</a>
                </li>
                <li class="accordion-subitem">
                  <a href="#">Подпункт three</a>
                </li>
                <li class="accordion-subitem">
                  <a href="#">Подпункт four</a>
                </li>
              </ul>
            </div>
          </div>
        </nav>

      </div>
      <div class="col col__article">
        [Контент]
      </div>
    </div>
  </div>
  <footer class="container footer">
    <div class="row">
      <div class="col col__footer">
        [Подвал]
      </div>
    </div>
  </footer>
</body>
              
            
!

CSS

              
                /*Обнуление*/
* {
  padding: 0;
  margin: 0;
  border: 0;
}

*,
*:before,
*:after {
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

:focus,
:active {
  outline: none;
}

a:focus,
a:active {
  outline: none;
}

nav,
footer,
header,
aside {
  display: block;
}

html,
body {
  height: 100%;
  width: 100%;
  font-size: 100%;
  line-height: 1;
  font-size: 14px;
  -ms-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  display: flex;
  flex-direction: column;
}

input,
button,
textarea {
  font-family: inherit;
}

input::-ms-clear {
  display: none;
}

button {
  cursor: pointer;
}

button::-moz-focus-inner {
  padding: 0;
  border: 0;
}

a,
a:visited {
  text-decoration: none;
}

a:hover {
  text-decoration: none;
}

ul li {
  list-style: none;
}

img {
  vertical-align: top;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-size: inherit;
  font-weight: 400;
}

/*//////////////////////////////////////////////////////////////////////////////////////////////////*/
/* контейнер */
.container {
  width: 100%;
  max-width: 1200px;
  padding-right: 15px;
  padding-left: 15px;
  margin-left: auto;
  margin-right: auto;
}

/* flex-контейнер */
.row {
  display: -ms-flexbox;
  display: flex;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
  margin-right: -15px;
  margin-left: -15px;
}

/* CSS настройки flex-элементов */
.col {
  position: relative;
  width: 100%;
  padding-right: 15px;
  padding-left: 15px;
}

/* ширина блоков article и aside по умолчанию */
.col__article,
.col__aside {
  -ms-flex: 0 0 100%;
  flex: 0 0 100%;
  max-width: 100%;
}

/* ширина блоков article и aside для больших экранов */
@media (min-width: 992px) {
  /* 2/3 от ширины контейнера */
  .col__article {
    -ms-flex: 0 0 66.666667%;
    flex: 0 0 66.666667%;
    max-width: 66.666667%;
  }

  /* 1/3 от ширины контейнера */
  .col__aside {
    -ms-flex: 0 0 33.333333%;
    flex: 0 0 33.333333%;
    max-width: 33.333333%;
  }
}

.header {
  background-color: #2f4f4f;
  flex: 0 0 auto;
  text-align: center;
  padding-top: 15px;
  padding-bottom: 15px;
}

.col__article {
  background-color: #fff8e1;
  padding-top: 20px;
  padding-bottom: 20px;
  text-align: left;
}

.col__aside {
  background-color: #dcedc8;
  padding-top: 20px;
}

.main {
  flex: 1 0 auto;
  display: flex;
}

.main .row {
  flex-grow: 1;
}

.footer {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  text-align: center;
  background-color: #2f4f4f;
  padding-top: 20px;
  padding-bottom: 20px;
  font-size: 16px;
}

.col__footer a {
  color: black;
}

/*///////////////////////////////////////////////////////////////////////////////////////////////*/

#accordion {
  display: none;
}

@media (min-width: 992px) {
  #accordion {
    display: block;
  }
}

.accordion-item {
  margin-bottom: 1px;
}

.accordion-item:last-child {
  margin-bottom: 0;
}

.accordion-item-header {
  /*Заголовки*/
  padding: 8px 8px 8px 20px;
  background: #4d5159;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  text-transform: uppercase;
  font-family: sans-serif;
  position: relative;
}

.accordion-item.show .accordion-item-header,
    /*Заливка при наведении на заголовок*/
    .accordion-item-header:hover,
    .accordion-item-header:focus {
  background: #3b3e44;
}

.accordion-item-header::before {
  /*Маленькая полоска в начале*/
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 10px;
  background: rgba(255, 255, 255, 0.5);
}

.accordion-item-header::after {
  /*Стрелочки*/
  content: "";
  position: absolute;
  top: 50%;
  right: 12px;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  background-size: cover;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 26.5 26.5' height='100' width='100'%3E%3Cpath d='M25.8 6.2l-1.2-1.3c-.5-.5-1-.7-1.6-.7a2 2 0 00-1.5.7l-8.3 8.4L5 4.9a2 2 0 00-1.6-.7c-.5 0-1 .2-1.5.7L.6 6.2c-.4.4-.6 1-.6 1.5 0 .7.2 1.2.6 1.6l11.1 11.2c.4.4 1 .7 1.5.7a2 2 0 001.6-.7l11-11.2c.4-.4.7-1 .7-1.6 0-.6-.3-1-.7-1.5z' fill='%23fff'/%3E%3C/svg%3E");
}

.accordion-item-content {
  display: none;
}

.accordion-item.show .accordion-item-content {
  display: block;
}

.accordion-item.show .accordion-item-header::after {
  transform: rotate(180deg);
}

.accordion-subitems {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

.accordion-subitem > a {
  /*Подзаголовки*/
  padding: 8px 8px 8px 20px;
  background: #dcdcdc;
  /*Фон подзаголовка*/
  color: #333;
  cursor: pointer;
  font-family: sans-serif;
  position: relative;
  margin-top: 1px;
  display: block;
  text-decoration: none;
  text-align: center;
}

.accordion-subitem > a::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 10px;
  background: #f4a460;
  /*Маленькая полоса у подзаголовка цвет*/
}

.accordion-subitem a:hover,
    /*Заливка при наведении на подзаголовок*/
    .accordion-subitem a:focus {
  background: #d4d3d5;
}

#nav-toggle {
  font-family: sans-serif;
  padding: 0.25rem 0.75rem;
  background-color: transparent;
  border: 1px solid rgba(0, 0, 0, 0.3);
  border-radius: 4px;
  width: 100%;
  margin-bottom: 20px;
  position: relative;
}

#nav-toggle::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 12px;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  background-size: cover;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 26.5 26.5' height='100' width='100'%3E%3Cpath d='M25.8 6.2l-1.2-1.3c-.5-.5-1-.7-1.6-.7a2 2 0 00-1.5.7l-8.3 8.4L5 4.9a2 2 0 00-1.6-.7c-.5 0-1 .2-1.5.7L.6 6.2c-.4.4-.6 1-.6 1.5 0 .7.2 1.2.6 1.6l11.1 11.2c.4.4 1 .7 1.5.7a2 2 0 001.6-.7l11-11.2c.4-.4.7-1 .7-1.6 0-.6-.3-1-.7-1.5z' fill='%23fff'/%3E%3C/svg%3E");
}

#nav-toggle.show::after {
  transform: rotate(180deg);
}

#nav-toggle.show ~ #accordion {
  display: block;
}

@media (min-width: 992px) {
  #nav-toggle {
    display: none;
  }
}


              
            
!

JS

              
                var accordion = (function (element) {
  var _getItem = function (elements, className) {
    // функция для получения элемента с указанным классом
    var element = undefined;
    elements.forEach(function (item) {
      if (item.classList.contains(className)) {
        element = item;
      }
    });
    return element;
  };

  return function () {
    var _mainElement = {}, // .accordion
      _items = {}, // .accordion-item
      _contents = {}; // .accordion-item-content

    var _actionClick = function (e) {
        if (!e.target.classList.contains("accordion-item-header")) {
          // прекращаем выполнение функции если кликнули не по заголовку
          return;
        }
        e.preventDefault(); // Отменям стандартное действие
        // получаем необходимые данные
        var header = e.target,
          item = header.parentElement,
          itemActive = _getItem(_items, "show");

        if (itemActive === undefined) {
          // добавляем класс show к элементу (в зависимости от выбранного заголовка)
          item.classList.add("show");
        } else {
          // удаляем класс show у ткущего элемента
          itemActive.classList.remove("show");
          // если следующая вкладка не равна активной
          if (itemActive !== item) {
            // добавляем класс show к элементу (в зависимости от выбранного заголовка)
            item.classList.add("show");
          }
        }
      },
      _setupListeners = function () {
        // добавим к элементу аккордиона обработчик события click
        _mainElement.addEventListener("click", _actionClick);
      };

    return {
      init: function (element) {
        _mainElement =
          typeof element === "string"
            ? document.querySelector(element)
            : element;
        _items = _mainElement.querySelectorAll(".accordion-item");
        _setupListeners();
      }
    };
  };
})();

var accordion1 = accordion();
accordion1.init("#accordion");

document.querySelector("#nav-toggle").onclick = function () {
  this.classList.toggle("show");
};


              
            
!
999px

Console