Css – How to make minimize, maximize, and close buttons for the website with CSS

buttoncssresizeweb serviceswindow

I would like to make Minimize, Maximize, and Close buttons for a modal box on a website I am creating. I want them to look like Windows 7 window buttons on my website. I have tried searching the web for help, but none of the sites gave me what I want. Please help me to build the buttons and use them.

Best Answer

Your best bet will be a modal library or a framework that has modals in it (such as bootstrap).

However if you're adamant on making your own, something like this will get you started. The key points of this are:

  • You need a modal that has a "header" separated from the content
  • You need JavaScript (jQuery will aide in this) to control the animations
  • This is something I slapped together, but the principles will apply to anything you build
    • Minimize needs to hide the content, NOT the header
    • Maximize needs to show the contnet, Not the header
    • Both buttons should ideally have an animation on click to show where the modal is going positionally.

jQuery(document).ready(function($){
  $(document).on('click', '.min', function(){
    $(this).closest('.modal').find('.content').slideUp();
    $(this).closest('.modal').animate({'left':0,'bottom':0});
  });
  
  $(document).on('click', '.max', function(){
    $(this).closest('.modal').find('.content').slideDown();
    $(this).closest('.modal').animate({'left':'20px','bottom':'50%'});
  });
  
  $(document).on('click', '.close', function(){
    $(this).closest('.modal').fadeOut();
  });
});
.shield {
  position: absolute;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,.25);
  top: 0;
  left: 0;
  font-family: sans-serif;
}

.modal {
  position: absolute;
  bottom: 50%;
  left: 20px;
  background: #fff;
  border: 1px solid #ccc;
  box-shadow: 0 0 15px -5px rgba(0,0,0,.5);
  width: 600px;
}

.modal .header {
  padding: 8px 12px;
  position: relative;
}

.modal .header .buttons {
  position: absolute;
  right: 0;
  top: 9px;
}

.modal .header .buttons span {
  border-left: 1px solid #ccc;
  padding: 8px 20px;
  cursor: pointer;
}

.modal .header .buttons span:hover {
  background: #eee;
}

.modal .content {
  border-top: 1px solid #ccc;
  padding: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
  <h1>Here's Content</h1>
  <p>Under the modal</p>
  <p>Under the modal</p>
  <p>Under the modal</p>
  <p>Under the modal</p>
</div>
<div class="shield">
  <div class="modal">
    <div class="header">
      <span>Modal Window</span>
      <span class="buttons"><span class="min">_</span><span class="max">[ ]</span><span class="close">X</span></span>
    </div>
    <div class="content">
    Here's modal pop-up content
    </div>
  </div>
</div>