Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <!-- https://forum.pasja-informatyki.pl/516317/jak-zakodowac-button?show=516540#a516540 -->

<div class="container">
  <section>
    <button class="main unchecked">Grupa 1</button>
  
    <button class="submain hidden" value="1-1">pozycja 1-1</button>
    <button class="submain hidden" value="1-2">pozycja 1-2</button>
    <button class="submain hidden" value="1-3">pozycja 1-3</button>
  </section>
</div>
<div class="container">
  <section>
    <button class="main unchecked">Grupa 2</button>
  
    <button class="submain hidden" value="2-1">pozycja 2-1</button>
    <button class="submain hidden" value="2-2">pozycja 2-2</button>
  </section>
</div>
<div class="container">
  <section>
    <button class="main unchecked">Grupa 3</button>
  
    <button class="submain hidden" value="3-1">pozycja 3-1</button>
    <button class="submain hidden" value="3-2">pozycja 3-2</button>
    <button class="submain hidden" value="3-3">pozycja 3-3</button>
    <button class="submain hidden" value="3-4">pozycja 3-4</button>    
  </section>
</div>

<div class="message-box hidden" data-action="">
  <span class="message"></span>
  <button value="ok">Ok</button>
  <button value="cancel">Cancel</button>
</div>
              
            
!

CSS

              
                .container {
  margin: 1em;
}
section {
  display: inline;
}
section button {
  font: 0.9em monospace;
  cursor: pointer;
  color: black;
  height: 2em;
  outline: none;
  border-radius: 0.5em;
  border: 1px solid gray;
  transition: all 0.1s;
}
section button.main {
  width: 6em;
  margin-right: 2em;
}
section button.submain {
  width: 8em;
  box-shadow: 1px 1px 1px rgba(0,0,0,0.4);
}
section button.submain:active {
  box-shadow: none;
}


.checked {
   box-shadow: none;
   color: lawngreen;
   background-color: seagreen;
   border-color: lawngreen;
}
.unchecked {
   box-shadow: 2px 2px 1px rgba(0,0,0,0.4);
}
.visible {
  visibility: visible;
}
.hidden {
  visibility: hidden;
}


.message-box {
  font: 1em monospace;
  margin: 1em;
  height: 1.4em;
}
.message-box button {
  font: 1em monospace;
  font-variant: small-caps;
  box-shadow: 1px 1px 1px rgba(0,0,0,0.4);
  margin: 0 0.2em;
  width: 4em;
  height: 1.5em;
  text-align: center;
  outline: none;
  border-radius: 0.5em;
  cursor: pointer;
}
.message-box button:hover {
  color: seagreen;
}
.message-box button:active {
  box-shadow: none;
}
              
            
!

JS

              
                const main_buttons = document.querySelectorAll('.main');
main_buttons.forEach((button) => {
  button.addEventListener('click', ( {target} ) => {
    if (target.classList.contains('checked')) {
      target.classList.remove('checked');
      target.classList.add('unchecked');
      subButtons('hidden', target);
      //messageBox('hide');
    } else {
      target.classList.remove('unchecked');
      target.classList.add('checked'); 
      subButtons('visible', target);
    }
  });
});

const section_buttons = document.querySelectorAll('.submain');
section_buttons.forEach((button) => { 
  button.addEventListener('click', ( {target} ) => {
    let text = 'Czy jesteś pewny że chcesz wybrać przycisk:';
    text = `${text} <b>${target.value}</b> ?`    
    messageBox('show', text, target.value);
  });
});

const message_box = document.querySelector('.message-box');
const message = document.querySelector('.message-box .message');
const message_box_buttons = document.querySelectorAll('.message-box button');

message_box_buttons.forEach((button) => {
  button.addEventListener('click', ( {target} ) => {
    switch(target.value) {
      case 'cancel':
        messageBox('hide');
        break;
      case 'ok':        
        const action = message_box.getAttribute('data-action');
        // tu akcja
        alert('Akcja dla: ' + action);
        /* swich(action) {
              case '1-1':
                dla przycisku <button value="1-1">
                break;
              . . .  
              case '3-2':
                dla przycisku <button value="3-2">
                break;
              itp.
           }
        */
        break;
    }
  });
});

function messageBox(cmd, msg='', action='') {
  let class_remove = '';
  let class_add = '';
  
  switch(cmd) {
    case 'show':
      class_remove = 'hidden';
      class_add = 'visible';
      break;
    case 'hide':      
      class_remove = 'visible';
      class_add = 'hidden';
      break;
  }
  
  message_box.setAttribute('data-action', action);
  message.innerHTML = msg;
  message_box.classList.remove(class_remove);
  message_box.classList.add(class_add);
}

function subButtons(cmd, target) {
  const section_buttons = target.closest('section');  
  if(!! section_buttons) {
    const sub_buttons = section_buttons.querySelectorAll('.submain');
    if(!! sub_buttons) {
      sub_buttons.forEach((sub_button) => {
        if(cmd == 'visible') {
          sub_button.classList.remove('hidden');
          sub_button.classList.add('visible');        
        } else {
          sub_button.classList.remove('visible');
          sub_button.classList.add('hidden');         
        }
      });
    }
  }
}
              
            
!
999px

Console